12-07-2015 01:13 PM
In general, when I import an SPSS data set (.sav) into SAS, all the labels and formats that were present in the original data set are present in SAS as well whenever I run any proc. It is often the case, though, that I need to make some modifications, and when I do, the original labels and formats disappear. Does anyone know why this happens?
proc import out = test file = "path.sav" dbms = spss replace;
new_var = ifn(old_var > 3,1,0,.);
So if the variable "old_var" was in the data set "test" and I create new_var and want to look at a crosstab of new_var and old_var2 (which I haven't done anything to in the new data set test_n). Whatever formatting and labels that were originally imported from the SPSS file are completely lost when I use the set statement (or somewhere in the creation of the new data set "test_n").
Any explanations or anything?
12-07-2015 02:07 PM
Yes, but if you don't do that, then it gives you an error that the formats are invalid.
You only need to remove the format of the problematic variable. format _all_ removes formats for ALL variables.
12-07-2015 03:09 PM
Labels are associated with specific variables. A new varaible does not inherit any label when using assignments in a datastep. Generally formats will not be associated from the variable in datastep code either. Exceptions could be basic character formats such as $8.
You need to assign the format or label. If you have multiple variables at least the formats are easy if they are the same:
Format Thisvar Thatvar anothervar mmddyy10. ; for example.
Need further help from the community? Please ask a new question.