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
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.
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;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.