DATA Step, Macro, Functions and more

Help with Macro

Reply
Contributor
Posts: 65

Help with Macro

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.
Super Contributor
Super Contributor
Posts: 365

Re: Help with Macro

Hello Pritish,

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

Sincerely,
SPR
Contributor
Posts: 65

Re: Help with Macro

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
Trusted Advisor
Posts: 1,301

Re: Help with Macro

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
Ask a Question
Discussion stats
  • 3 replies
  • 125 views
  • 0 likes
  • 3 in conversation