Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SAS Passing Multiple User Input Values to Macro Variable

I am using SAS Web Report Viewer where I have an interface from which end users can select the multiple values as an input to a macro variable. However, when I check the SAS Logs I see that only the first input value is passed on to the macro variable. How can I get all the values passed on to the macro variable? (And if possible separate the values using ‘|’ as a delimiter). For example here I am trying to pass ‘Discount_Logility’ and ‘Discount_EDD’ as the inputs to the variable ‘list_string’ (I want the variable to dynamically take in more inputs depending on how many the user passes).

%put &list_string;

Here is the SAS Log

>>> SAS Macro Variables:

 LIST_STRING=Discount_Logility
 LIST_STRING0=2
 LIST_STRING1=Discount_Logility
 LIST_STRING2=Discount_EDD
 LIST_STRING_COUNT=2

But here we can see that the macro variable ‘list_string’ takes only the first input, ‘Discount_Logility’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

21        +%put &list_string;
Discount_Logility

How can value of ‘list_string’ variable be list_string = Discount_Logility | Discount_EDD OR whatever be the best way to pass in the multiple inputs to the list_string variable.

>Solution :

SAS passes each one into its own macro variable. Note these three entries in the log:

LIST_STRING1=Discount_Logility
LIST_STRING2=Discount_EDD
LIST_STRING_COUNT=2

You can use LIST_STRING_COUNT and iterate over all the selections.

%macro convert_to_list;
    %global list_string;
  
    %let list_string = &list_string1;

    %do i = 2 %to &list_string_count.;
        %let list_string = &list_string.|&&list_string&i.;
    %end;
%mend;

%convert_to_list;

%put &list_string;
Discount_Logility|Discount_EDD
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading