BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
narulap
Obsidian | Level 7

Hello,

 

I have created a text prompt "Variable_List" with Multiple Values. I want to resolve this Text Type macro in my code.

Prompt.PNG

Previously, I was using limited number of variables with manual input in the macro variable " varlist".

 

%let varlist = TBM_STAGE1 TBM_STAGE2 SHIFT_BUILD_DATE BLADDER;

I was using the below format for count and then loop across these variables to get the output.

 

/*4.Looping through the Variables and checking the Data Type with Put Statement at the end*/
		%do I=1 %to %sysfunc(countw(&varlist)); 
					%let var = %scan(&varlist, &I);

My question is I just have to Substitute the &varlist with &Variable_List. in the Do statement? Kindly let me know if you need further input.

 

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

SAS creates an additional variable named "Variable_List_Count" and sets it to the number of values selected. If more than one value was selected, than the values are in the variables "Variable_List1", "Variable_List2" ...

 

The following step should create the macro-variable varlist in the already used format.

data _null_;
   length varList $ 1000;

   do i = 1 to &Variable_List_Count.;
      if i = 1 then do;
         varlist = catx(' ', varList, symget("Variable_List"));
      end;
      else do;
         varlist = catx(' ', varList, symget(cats("Variable_List", i)));
      end;
   end;

   call symputx('varList', varList);
run;

View solution in original post

2 REPLIES 2
andreas_lds
Jade | Level 19

SAS creates an additional variable named "Variable_List_Count" and sets it to the number of values selected. If more than one value was selected, than the values are in the variables "Variable_List1", "Variable_List2" ...

 

The following step should create the macro-variable varlist in the already used format.

data _null_;
   length varList $ 1000;

   do i = 1 to &Variable_List_Count.;
      if i = 1 then do;
         varlist = catx(' ', varList, symget("Variable_List"));
      end;
      else do;
         varlist = catx(' ', varList, symget(cats("Variable_List", i)));
      end;
   end;

   call symputx('varList', varList);
run;
narulap
Obsidian | Level 7

Perfect!!! Thanks @andreas_lds for explaining the concept behind the  work and the code is working exactly what I needed Smiley Happy

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
  • 2 replies
  • 1490 views
  • 1 like
  • 2 in conversation