BookmarkSubscribeRSS Feed
DPraba79
Calcite | Level 5
Hi,
i would like to store the number observation printed by PROC PRINT into a macro variable. Could you please let me know how will i get it. For Ex, i want to store the number of OBS for below statement.

PROC PRINT DATA=DATA1; WHERE CUST_NAME ='PRABA';RUN;
1 REPLY 1
Cynthia_sas
Diamond | Level 26
Hi:
See this previous forum posting for an idea of how macro variable creation works in general:
http://support.sas.com/forums/thread.jspa?messageID=8249‹

and then study this modification of that previous program:
[pre]
proc sql;
select count(name) into :cntobs
from sashelp.class
where age ge 15;
quit;

%let cntobs = &cntobs;
%put cntobs= &cntobs is the number of obs in SASHELP.CLASS;
%put where age was greater than or equal to 15;

ods listing;
proc print data=sashelp.class N;
title "Students who meet the criteria: &cntobs";
where age ge 15;
run;
[/pre]
which produces this output:
[pre]
Students who meet the criteria: 5

Obs Name Sex Age Height Weight

8 Janet F 15 62.5 112.5
14 Mary F 15 66.5 112.0
15 Philip M 16 72.0 150.0
17 Ronald M 15 67.0 133.0
19 William M 15 66.5 112.0

N = 5

[/pre]

Note how the number from &CNTOBS used in the title is equal to the N= that is put into the PROC PRINT (after the detail listing).

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1 reply
  • 892 views
  • 0 likes
  • 2 in conversation