BookmarkSubscribeRSS Feed
saslove
Quartz | Level 8

Is there a way to bring the value from a PROC FREQ output dataset into a PROC REPORT header? 

 

For ex: 

 

proc freq data=data;
tables cohort/out=cohortct (drop=percent rename=count=cohortct);
run;

data cohortct;
set cohortct;
cohortct2=strip(cohort||' (N='||(strip(cohortct)||')'));
put cohortct2;
run;

 

I need to display COHORTCT2 in a column header in PROC REPORT.

This is the value of COHORTCT2 

1A (N=4)
1B (N=7)


proc report data=table1 split="|" ;
column cohort number1 ;
define cohort/display center style(column)={width=1in} 'Cohort I need the numbers for COHORTCT here';
define number1 /display right style(column)={width=.5in} 'Subjects experiencing Grade 1';
run;

 

How can this be done? 

 

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20

How about

data COHORTCT;
  set COHORTCT;
  COHORTCT2=strip(COHORT||' (N='||(strip(COHORTCT)||')'));
  call symputx ('cohortct2',COHORTCT2);
run;
 
proc report data=TABLE1 split="|" ;
  column COHORT NUMBER1 ;
  define COHORT/display center style(column)={width= 1in} "Cohort &cohortct2";
  define NUMBER1/display right style(column)={width=.5in} 'Subjects experiencing Grade 1';
run;

?

saslove
Quartz | Level 8
It only displays &cohortct2 on the column header. It doesn't display the
numbers I want.
ChrisNZ
Tourmaline | Level 20

Did you copy the code as is?  Including the double quotes?

saslove
Quartz | Level 8

You are right. The double quote did work - but the problem is it only keeps the second row. 

I need

1A (N=4)
1B (N=7)

on the column header. But it only shows the second row, 1B (N=7).

 

Do you know why? 

ChrisNZ
Tourmaline | Level 20

it only keeps the second row. Do you know why? 

 

Because that's what you programmed.

I reckon the easiest is for you to create two macro variables

if _N_=1 then call symput...

if _N_=2 then call symput...

saslove
Quartz | Level 8
Ok yes I created where statements and it worked perfectly. Thanks so much for your response.

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
  • 6 replies
  • 987 views
  • 0 likes
  • 2 in conversation