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

Dear Experts

 

%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;

 

  proc iml;
    s="&xtemplist";
    delims = ' ';
    n = countw(s, delims);
    xtemplist1 = scan(s, 1:3, delims);

    xtemplist2 = scan(s, 4:n, delims);
    print xtemplist1;
    call symput("t",xtemplist1);

    call symput("t1",xtemplist2);
  quit;

%put &t;  

%put &t1;  


>> t-->only CO is displayed. How to get BA EN CO?     

t1->>TRA is displayed. How to get CA SV IN UT TRA?

 

Thank you for your help

:LL

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Here's a way that keeps all the processing under the control of macro language. 

 

%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;

 

%macro split (n=3);

 

%GLOBAL XTEMPLIST1 XTEMPLIST2;

%let xtemplist1=;

%local i;

 

%do i=1 %to &n;

   %let xtemplist1 = &xtemplist1 %scan(&xtemplist, &i);

%end;

 

%let xtemplist2 = %substr(xtemplist, %length(&xtemplist1) + 1);

 

%mend split;

 

%split (n=3)

 

Because of the %do loop, you will need to define a macro.  On the other hand, you gain the advantage of being able to control how many words are selected into the first variable.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

Here's a way that keeps all the processing under the control of macro language. 

 

%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;

 

%macro split (n=3);

 

%GLOBAL XTEMPLIST1 XTEMPLIST2;

%let xtemplist1=;

%local i;

 

%do i=1 %to &n;

   %let xtemplist1 = &xtemplist1 %scan(&xtemplist, &i);

%end;

 

%let xtemplist2 = %substr(xtemplist, %length(&xtemplist1) + 1);

 

%mend split;

 

%split (n=3)

 

Because of the %do loop, you will need to define a macro.  On the other hand, you gain the advantage of being able to control how many words are selected into the first variable.

Ksharp
Super User

HoHo. You are doing this under IML code. You really want do this via IML ?

 

%let XTEMPLIST  =  BA EN CO CA SV IN UT TRA;
 
  proc iml;
    s="&xtemplist";
    delims = ' ';
    n = countw(s, delims);
    xtemplist1 = scan(s, 1:3, delims);
    xtemplist2 = scan(s, 4:n, delims);
    print xtemplist1;
    call symput("t",rowcat(xtemplist1+' '));
    call symput("t1",rowcat(xtemplist2+' '));
  quit;
%put &t;  
%put &t1;  

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!

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
  • 2 replies
  • 5129 views
  • 0 likes
  • 3 in conversation