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

I want to run the following code. My problem is that I dont know how to put the delimiter in the scan function so that it identifies the three variables inside vars. I've tried multiple times without success (I just put "?" inside the code because that is were my question lies). I hope you can help me. Thanks in advance.

 

%let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n;

 

%macro serie;

    

     %do i=1 %to 3;

         

          %let parameter=%scan(&vars.,&i.,"?");

 

          proc sgplot data=base;

          series x=date y=&parameter./ markers;

          run;

 

     %end;

 

%mend;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use the Q modifier on the %SCAN() call.

128  %let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n;
129  %put %scan(&vars,1,%str( ),q);
"TIIE 28 días (%)"n
130  %put %scan(&vars,2,%str( ),q);
"TIIE 91 días (%)"n
131  %put %scan(&vars,3,%str( ),q);
"Cetes 28 días (%)"n

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

Use the Q modifier on the %SCAN() call.

128  %let vars="TIIE 28 días (%)"n "TIIE 91 días (%)"n "Cetes 28 días (%)"n;
129  %put %scan(&vars,1,%str( ),q);
"TIIE 28 días (%)"n
130  %put %scan(&vars,2,%str( ),q);
"TIIE 91 días (%)"n
131  %put %scan(&vars,3,%str( ),q);
"Cetes 28 días (%)"n
alejandrogrrl
Fluorite | Level 6

Thanks a lot! This is exactly what I needed. I'm really really grateful.

ballardw
Super User

Since your values have default delimiters like spaces then you need to construct the variable list with a known character like a pipe character | or some other character that you will absolutely never ever use in a variable name.

 

%let vars="TIIE 28 días (%)"n|"TIIE 91 días (%)"n|"Cetes 28 días (%)"n;

%let v1 = %scan(&vars,1,|);
%let v2 = %scan(&vars,2,|);
%let v3 = %scan(&vars,3,|);

%put &v1.;
%put &v2.;
%put &v3.;

Please note that since the macro language uses % for functions and such you may have other issues further on. Also, inclusion of characters like comma or & in your variable names is extremely likely to be problematic.

In the long run you would be much better off using standard variable names and use a variable LABEL to provide "nicer" text for output.

alejandrogrrl
Fluorite | Level 6
Thanks for the solution.

I know using commas and symbols in variable names is extremely uncovenient. However, since these variables are from a public source (my central bank) I was asked not to change the names of the variables.

Thanks again for the solution and for the tips!

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2110 views
  • 2 likes
  • 4 in conversation