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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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