BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
shonn2nd
Fluorite | Level 6

Dear all, 

 

I have a question. After I import data set from SPSS into SAS, SAS VIEWTABLE will only show the value labels of survey items (if those items have value labels). SPSS allows you to switch back and forth between value and value labels by click a button on the tool bar. I am wondering how I can switch back and forth between value and value labels in my data set in SAS. Only showing value labels gives me difficulty to see the correspondence between value labels and values. Although SAS treats Likert scale items as numeric variables, when I try proc freq, the output will only show value labels without any information about the original values. Thank you for any help.  

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You can use the FORMAT statement without any format specification to remove the format associated with a variable.

proc freq data=mydata;
  tables myvar;
  format myvar;
run;

We used to make two format catalogs with the same format definition. In one the formatted value included the original value. 

proc format lib=mylib.formats;
value myfmt 1='Low' 2='High';
run;
proc format lib=mylib.cformats;
value myfmt 1='1 Low' 2='2 High';
run;

Then you could switch between which format definition SAS would use by changing the FMTSEARCH option. Somewhere I even have a macro that will read a format catalog and generate a new format catalog with the formats re-defined to include the codes as part of the decodes.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

You can use the FORMAT statement without any format specification to remove the format associated with a variable.

proc freq data=mydata;
  tables myvar;
  format myvar;
run;

We used to make two format catalogs with the same format definition. In one the formatted value included the original value. 

proc format lib=mylib.formats;
value myfmt 1='Low' 2='High';
run;
proc format lib=mylib.cformats;
value myfmt 1='1 Low' 2='2 High';
run;

Then you could switch between which format definition SAS would use by changing the FMTSEARCH option. Somewhere I even have a macro that will read a format catalog and generate a new format catalog with the formats re-defined to include the codes as part of the decodes.

ballardw
Super User

One of the very nice things about SAS Formats is that they can be applied at use time and do not need to modify an existing data set to change the display (value label) for another use or procedure. The example below creates two custom formats to group ages in different ways and then uses the custom format with Proc Freq to create groups to count. Almost all of the analysis procedures in SAS will honor groups created with formats. The last Proc Freq uses a SAS supplied format to display the age quite differently.

 

Note that you should have the SASHELP.Class data set available and that the data set is not modified in any way.

proc format library=work;
value age_3yrgrp
 10 - 12 = '10 to 12'
 13 - 15 = '13 to 15'
 16 - 18 = '16 to 18'
 ;
 value age_2grps
 low - 14 ='14 or less'
 14<-high ='Greater than 14'
 ;
run;

proc freq data=sashelp.class;
   tables age;
   format age age_3yrgrp.;
run;
proc freq data=sashelp.class;
   tables age;
   format age age_2grps.;
run;
proc freq data=sashelp.class;
   tables age;
   format age Roman5.;
run;

The formats can become extremely powerful when used with dates, time and datetimes as you can get summaries by calendar year, calendar quarter, calendar month, month across years, week of year or week just by changing formats.

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2577 views
  • 3 likes
  • 3 in conversation