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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1247 views
  • 0 likes
  • 2 in conversation