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);
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.
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.
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.
@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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: