I run PROC SURVEYFREQ to get the frequencies for two age groups. The output from PROC SURVEYFREQ has the label of my age_group variable which is "How old are you?". However, the only output data from my PROC SURVEYFREQ: OneWay=Output does not show the label of the variable anymore. I want to use the output from my ODS OUTPUT step in a report and I would like to keep the label for my original variable. I have so many variables and I would like to use a macro and not type the labels as a TITLE or one by one.
Alternatively, if I can remove the first row of my PROC SURVEYFREQ table, or edit its content (to remove the "Table of age_group" part and keep only the "How old are you" part), I use that one instead of the output from ODS OUTPUT.
Thanks
ods trace on;
proc surveyfreq data = &dataset VARHEADER = NAMELABEL nosummary;
tables age_group/cl nofreq nostd;
weight &weight_var;
run;
ods trace off;
Table of age_group(How old are you?) | ||||
---|---|---|---|---|
age_group(How old are you?) | Weighted Frequency |
Percent | 95% Confidence Limits for Percent |
|
10-15 | 126 | 50.9 | 48.3 | 53.5 |
16-20 | 121 | 49.1 | 46.5 | 51.7 |
Total | 247 | 100.0 |
ods output OneWay=Output;
proc surveyfreq data = &dataset VARHEADER = NAMELABEL nosummary;
tables age_group/cl nofreq nostd;
weight &weight_var;
run;
proc print data=output; run;
Obs | Table | F_age_group | age_group | WgtFreq | Percent | LowerCL | UpperCL | _SkipLine |
---|---|---|---|---|---|---|---|---|
1 | Table age_group | 10-15 | 10-15 | 126 | 50.9 | 48.3 | 53.5 | |
2 | Table age_group | 16-20 | 16-20 | 121 | 49.1 | 46.5 | 51.7 | |
3 | Table age_group | Total | . | 247 | 100.0 | _ | _ | 1 |
data output;
set output;
label = vlabelx(scan(table,2,' '));
run;
data output;
set output;
label = vlabelx(scan(table,2,' '));
run;
The value of variable TABLE is the text string
Table age_group
and so scan(table,2,' ') finds the second "word", which is the text string age_group
Have you checked that the variable label is empty?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.