Skip to content

Instantly share code, notes, and snippets.

@masnick
Last active December 19, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masnick/5876361 to your computer and use it in GitHub Desktop.
Save masnick/5876361 to your computer and use it in GitHub Desktop.
Convert SAS formats to Stata labels.
value Fgender
1='male'
2='female';
value Fyesno
1='yes'
0='no';
# Convert SAS formats to Stata labels.
#
# SAS formats must be in the following format:
#
# value Fgender
# 1='male'
# 2='female';
#
# Note that format names are the same as variable names but
# with `F` prepended.
test = IO.read('formats.sas')
matches = test.scan /value (.*)\s+(([0-9]+='.*'[\s;]*)*)/
matches.each do |match|
matches2 = match[1].scan /[0-9]+='.*'[\s;]*/
print "la de #{match[0]}"
matches2.each do |match2|
matches3 = match2.match /([0-9]+)='(.*)'/
print " #{matches3[1]} \"#{matches3[2]}\""
end
print "\n"
puts "la val #{match[0][1..-1]} #{match[0]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment