data test;
input id fname $4. lname $5. age;
cards;
123 abc1 def1 24
124 abc2 def2 25
125 abc3 def3 26
;
run;
in proc report how to get output below based upon condition ?
if id = 123 then display only fname and lname
fname lname
abc1 def1
abc2 def2
abc3 def3
if id = 124 then display only fname
fname
abc1
abc2
abc3
if id = 125 then display only age
age
24
25
26
Data step to do the IF conditions, then PROC PRINT. Yes, you can probably do all of this in PROC REPORT but it is much simpler in a DATA step followed by PROC PRINT.
I wolud like to do proc report because i have to summarize , total summarize too
caould you please help ?
What exact type of 'summarize' is involved?
Many users that don't read the help don't realize that Proc Print will do sums of numeric variables. Look at SUM, SUMBY statements.
@mmkr wrote:
I wolud like to do proc report because i have to summarize , total summarize too
caould you please help ?
Hi:
Your only numeric variables are ID and AGE. Are you going to summarize AGE? That doesn't seem to serve any purpose. However, you'd need to make all your changes in a COMPUTE block. Here's an example, just keep in mind that the reason for having all the IF statements in the COMPUTE block for WEIGHT is that all the variables have been placed on the report row by the time the COMPUTE block for WEIGHT will be executed, so rather than having separate IF statements in separate COMPUTE blocks for each variable, you can do it all in the COMPUTE block for the last variable. Note that the reason WEIGHT is not summarized is that it is defined as a DISPLAY item on the report. So only AGE and HEIGHT will be summarized.
options missing=' ';
proc report data=sashelp.class;
column name sex age height weight;
define name / order;
define sex / display;
define age / analysis;
define height / analysis;
define weight / display;
rbreak after / summarize;
compute weight;
if name = 'Alfred' then do;
sex = ' ';
weight = .;
call define('sex','style','style={background=yellow}');
call define('weight','style','style={background=yellow}');
end;
else if name = 'Barbara' then do;
weight = .;
call define('weight','style','style={background=yellow}');
end;
else if name = 'John' then do;
sex = ' ';
weight = .;
call define('sex','style','style={background=yellow}');
call define('weight','style','style={background=yellow}');
end;
endcomp;
run;
I added the yellow highlighting so it was visible what had been "turned off" in each of the 3 report rows.
Cynthia
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.