BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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);

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 245 views
  • 1 like
  • 4 in conversation