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: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 5 replies
  • 2064 views
  • 2 likes
  • 4 in conversation