BookmarkSubscribeRSS Feed
Uknown_user
Quartz | Level 8

Hello,

 

I tried to make a macro with one variable where one can define quantile (e.g. flag data with appropriate mark - for example: in case it belongs to the lowest decile as Q10, etc.). The script does not store all values of i, it goes from 1 to the defined number N but then only stores the last result (i.e. N), any suggestions how to keep all values of i and thus gain all cases?:

 

%MACRO M(N);

DATA _NULL_;

%DO i=1 %TO &N.;

PROC SQL;

CREATE TABLE G AS

SELECT VAR1,

VAR2,

CASE WHEN VAR2 <= (1-(&i-1)/10) * MAX(VAR2) AND VAR2> (1-&i/10) * MAX(VAR2) THEN "Q&i" END AS FLAG

FROM B;

QUIT;

%END;

%MEND M;

%M(10)

 

Thanks for any suggestions.

 

Jiri

4 REPLIES 4
Astounding
PROC Star

Many ideas, but just one suggestion to start.  Get the program to work by hard-coding everything, without using macro language.  Once it is working, we can look at converting it into a macro.

 

Unless you do that, you will have to debug both SAS language errors and macro language errors at the same time ... a much more difficult task.

Uknown_user
Quartz | Level 8

It appears like I will indeed have to do that. Thanks

Reeza
Super User

Use a data step and array - a single data step. 

Macros will just make this complicated. 

Reeza
Super User

And proc rank wouldn't work either? 

If you want indicators for deciles you'll need to transpose the final table but again it's fully dynamic without macros. 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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