BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Emma_at_SAS
Lapis Lazuli | Level 10

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;

 

The SURVEYFREQ Procedure
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
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data output;
    set output;
    label = vlabelx(scan(table,2,' '));
run;
--
Paige Miller

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26
data output;
    set output;
    label = vlabelx(scan(table,2,' '));
run;
--
Paige Miller
Emma_at_SAS
Lapis Lazuli | Level 10
Thank you, Paige Miller! It works perfectly! May you please help me to understand the scan(table,2,' ') part?
PaigeMiller
Diamond | Level 26

 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

--
Paige Miller
ChrisNZ
Tourmaline | Level 20

Have you checked that the variable label is empty?

Emma_at_SAS
Lapis Lazuli | Level 10
Thank you, ChrisNZ. Yes, the variable labels are there. The code from Paige Miller adds a column with the label.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 848 views
  • 2 likes
  • 3 in conversation