Last active
December 19, 2015 01:29
-
-
Save masnick/5876361 to your computer and use it in GitHub Desktop.
Convert SAS formats to Stata labels.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value Fgender | |
1='male' | |
2='female'; | |
value Fyesno | |
1='yes' | |
0='no'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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