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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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