BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

User define macro variable in structure  as following:

1 or 2 digits number _4 digits number _  4 digits number

for example:

%let  X=59_2001_9901;

%let  X=8_2001_9901;

I want to create another macro variable called Y that is created automatically from macro variable X and get the digits of macro variable X  before the first underscore.

So in the examples  :

%let Y=59;

%let Y=8;

May you show code how to do it please?

6 REPLIES 6
yabwon
Onyx | Level 15

Or even just:

 

%let y = %scan(&x.,1,_);

 

[EDIT:] Link to the doc. https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/p1nhhymw6gxixvn1johcfl6kaygw.htm

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

;-D

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



u48512177
Fluorite | Level 6

%let X=59_2001_9901;
%let Y=%sysfunc(scan(&X, 1, _));
%put Y=&Y;

 

%let X=8_2001_9901;
%let Y=%sysfunc(scan(&X, 1, _));
%put Y=&Y;

 

u48512177_0-1684233698632.png

 

yabwon
Onyx | Level 15

?

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 601 views
  • 4 likes
  • 4 in conversation