BookmarkSubscribeRSS Feed
Pritish
Quartz | Level 8
Hi,

Currently, I am having two proc sql statement where one get's the count of the data and the other sql query creates a new table based on that count. I am trying to create a macro as both the query as same but not able to figure how can I achieve both results?

Any suggestions would be highly appreciated.
3 REPLIES 3
SPR
Quartz | Level 8 SPR
Quartz | Level 8
Hello Pritish,

If you would like a detailed answer, please give an example of data, desired result and your code.

Sincerely,
SPR
Pritish
Quartz | Level 8
1.
proc sql;
select count (distinct emp) into: emp_cnt
from emp;
quit;

2.
proc sql;
create table emp_new as
select count (distinct emp) as emp_cnt
from emp;
quit;


I have this two queries. I want to avoid unnecessary code so trying to go for Macro. Message was edited by: Pritish
FriedEgg
SAS Employee
I don't really see a macro being necessary to accomplish this task.

data emp_new;
set emp end=eof;
if eof=1 then do;
emp_cnt=_N_;
call symput('emp_cnt',emp_cnt);
keep emp_cnt;
output;
end;
run;

The above should create dataset emp_new containing one column (emp_cnt) and one row containing the count of rows in emp, while also putting the count into variable &emp_cnt. Above is untested but assumed to work. Message was edited by: mkastin

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 1366 views
  • 0 likes
  • 3 in conversation