BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mango_tango_598
Fluorite | Level 6

Hello,

 

Please help me to set up macro to do 'proc npar1way' analysis. I have 20 variables in 'dicom_cat', and I would like to set up 'class' by selecting 1 variable from 'dicom_cat' each time for the analysis. So far, I've got SAS codes like these but it is not working... Please help me how I should set them up. Thank you very much!

%macro KWloop(class= );	
%let count=1;
%do %until (%scan(&dicom_cat, &count)=);
%let x=%scan(&dicom_cat, &count);
proc npar1way data=&dsn;
class &x;
var &feature_vars;
run;
%let count=%eval(&count+1); %end; %mend KWloop; %KWloop (class=1);
1 ACCEPTED SOLUTION

Accepted Solutions
mango_tango_598
Fluorite | Level 6

Thank you very much for the response! I am so sorry that I did not explain well about my dataset. I figured it out much easier way without using loop. 

View solution in original post

3 REPLIES 3
ballardw
Super User

What is the value of &dicom_cat? Where is it set?

 

Checking for "blanks" in the macro language is not trivial.

IF &dicon_cat is a space delimited list like: thisvar thatvar anothervar

then I would write something more like:

%macro KWloop( );	
  
   %do i = 1 %to %sysfunc(countw,&dicom_cat.); 
      %let x=%scan(&dicom_cat., &i.);
      proc npar1way data=&dsn;
      class &x;
      var &feature_vars;
      run;

   %end;
%mend KWloop;

Personally I would make Dicom_cat the parameter of the macro.

 

The above loops over every variable in the list, if Dicom_cat is an actual list of variables and calls the procedure once with with each variable as a Class variable.

 

It is poor form to just have macro variables, such as Dicom_cat or Feature_var magically appear in the middle of code, especially  if there is no mention of where the values are set or what they should contain.

 

If you are thinking of extending this to groups of 2 or 3 or more more variables I would suggest using a data step to write the code to a text file and %include that file after verifying the code works. I suggest that approach because of the functions like allcombi that will create combinations and permulations of values. Writing to the text file to document what you run and have it is a model for the next time.

mango_tango_598
Fluorite | Level 6

Thank you very much for the response! I am so sorry that I did not explain well about my dataset. I figured it out much easier way without using loop. 

ballardw
Super User

@mango_tango_598 wrote:

Thank you very much for the response! I am so sorry that I did not explain well about my dataset. I figured it out much easier way without using loop. 


You should share your solution. That way anyone else landing here from a search for a similar question can see if your solution would work for them.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 442 views
  • 0 likes
  • 2 in conversation