BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello,

Let's say that I want to run a macro and there are 9 runs.

Is there a clever way to run it in less code rows?

Please note that 1812/1806/1801 are dates in form YYMM.

 

%Dist(1812,Cars_Consume1812, "Cars_consume");
%dist(1806,Cars_Consume1806, "Cars_consume");
%dist(1801,Cars_Consume1801, "Cars_consume");

%dist(1812,cars_age1812, "cars age in years");
%dist(1806,cars_age1806, "cars age in years");
%dist(1801,cars_age1801, "cars age in years");

%dist(1812,Car_engine_size1812,  "Car Engine size");
%dist(1806,Car_engine_size1806,  "Car Engine size");
%dist(1801,Car_engine_size1801,  "Car Engine size");
3 REPLIES 3
PaigeMiller
Diamond | Level 26

I don't know what %DIST does, but I'm sure we have discussed putting your data into a good format for analysis. In particular, putting calendar information into variable names is a bad idea, which requires more coding effort, as you can see in this example. On the other hand, if your calendar YYMM was contained in a variable in the data set, you could use BY statements or something like PROC SUMMARY and then you don't even have to specify what months you want.

 

Is there a clever way to run it in less code rows?

 

Yes, arrange your data into a better format, then multiple analyses will be simple. Maxim 19. Maxim 33.

--
Paige Miller
Reeza
Super User

Does your code go beyond what's shown? For 9 calls any more attempts at efficiency will likely be the same amount of code. 

 

SASKiwi
PROC Star
%macro Run_Dist (Dist_Type=);

%Dist(1812,Cars_Consume1812, "&Dist_Type");
%Dist(1806,Cars_Consume1806, "&Dist_Type");
%Dist(1801,Cars_Consume1801, "&Dist_Type");

%mend Run_Dist;

%Run_Dist (Dist_Type=Cars_consume);
%Run_Dist (Dist_Type=Cars age in years);
%Run_Dist (Dist_Type=Cars Engine size);
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
  • 777 views
  • 1 like
  • 4 in conversation