BookmarkSubscribeRSS Feed
icipeb
Fluorite | Level 6

Hello!

 

Using a macro, I am producing a series of crosstabs using several demographic variables (sex, age, income, etc.). Some of these variables have formats I created using PROC FORMAT.

 

When I use PROC SURVEYFREQ, the ods output provides a table with a column that contains the values (say sex contains values 1 or 2) and another column with the formatted value (say F_sex contains Male or Female). I use the formatted columns and rename them Demographic.

 

I then append the files created with ods output and I obtain a column named Demographic that  contains the formatted values (ex. Male, Female, 18 to 30, 31 to 40, et.).

 

However, when I do the same with PROC SURVEYMEANS, the ods output does not include columns with formatted values only columns with the actual values such as 0 and 2 and not Male and Female).

 

Is there a way to force ods output to include the formatted values?

 

Thanks in advance for your help!

 

* Both PROC steps are part of a macro and &DemoVar contains the demographic variable ;
proc surveyfreq data=Mydataset	VARHEADER=LABEL	;

tables  year * &DemoVar * fg_use_choose
		year * &DemoVar * fg_use_amt
		year * &DemoVar * fg_use_assess
		year * &DemoVar * fg_use_plan
		year * &DemoVar * fg_use_wt
		year * &DemoVar * fg_use_away	/ nostd  row 	; 

weight  wght	;

format	income_adeq_G	income_adeq_G_F.
		fg_use_choose
		fg_use_amt
		fg_use_assess
		fg_use_plan
		fg_use_wt
		fg_use_away	yesno_F.	;

ods output CrossTabs=Results_Info	;

run	;

***********************************************;
proc surveymeans data=Mydataset	mean VARHEADER=LABEL	plots = none	;

var  FG_trust 	;

domain year * &DemoVar year	;

weight  wght	;

format	income_adeq_G	income_adeq_G_F.	;

ods output Domain=Results_Trust	;

run	;

Erik

2 REPLIES 2
ballardw
Super User

As far as I can see you want to take the results from the Proc Surveymeans through a data step to add the new variable using the format.

 

Note: you can save some coding by using the grouping syntax in the Tables statement.

This should be equivalent yours:

tables  (year * &DemoVar) * ( fg_use_choose
                              fg_use_amt
                              fg_use_assess
                              fg_use_plan
                              fg_use_wt
                              fg_use_away)	/ nostd  row 	; 

And in my code for my projects

tables  year * ( <list of demovars>) * ( fg_use_choose
                              fg_use_amt
                              fg_use_assess
                              fg_use_plan
                              fg_use_wt
                              fg_use_away)	/ nostd  row 	; 

and only make one call to survey freq with those fg variables. That may be a style choice to avoid multiple data sets.

 

data_null__
Jade | Level 19

If I understand correctly, you need a data step and the VVALUE function and a RENAME.  This can be automated to some extent with a macro.   

 

proc format;  
   value $sex 'F'='Female' 'M'='Male';
   value age(multilabel) 11-12='Pre-teen' 13-16='Teen';
   quit;
proc surveymeans data=sashelp.class mean VARHEADER=LABEL	plots = none	;
   var  weight;
   domain age * sex age;
   *weight ;
   format sex $sex. age age.;
   ods output Domain=domain;
   run;

proc contents;
   run;
data domain;
   set domain;
   length f_age $10;
   f_age = vvalue(age);
   rename f_age=age age=n_age;
   run;
proc print;
   format _all_;
   run;

image.png

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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 187 views
  • 0 likes
  • 3 in conversation