Why do labels and format disappear?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

Why do labels and format disappear?

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?

 

Example code:

 

proc import out = test file = "path.sav" dbms = spss replace;

run;

 

data test_n;

    set test;

    format _ALL_;

 

new_var = ifn(old_var > 3,1,0,.);

run;

 

 

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?

 

Thanks!


Accepted Solutions
Solution
‎12-07-2015 03:12 PM
Respected Advisor
Posts: 3,124

Re: Why do labels and format disappear?

Or try:

 

options NOFMTERR;

View solution in original post


All Replies
Respected Advisor
Posts: 3,124

Re: Why do labels and format disappear?


 

Any explanations or anything?

 


format _ALL_;

Occasional Contributor
Posts: 11

Re: Why do labels and format disappear?

Yes, but if you don't do that, then it gives you an error that the formats are invalid.
Respected Advisor
Posts: 3,124

Re: Why do labels and format disappear?


mmraja wrote:
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.

Solution
‎12-07-2015 03:12 PM
Respected Advisor
Posts: 3,124

Re: Why do labels and format disappear?

Or try:

 

options NOFMTERR;
Grand Advisor
Posts: 10,251

Re: Why do labels and format disappear?

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 318 views
  • 0 likes
  • 3 in conversation