BookmarkSubscribeRSS Feed
Almoha
Calcite | Level 5

All, 

 

I have the following values in a variable VAR1. Need to create a variable VAR2 and populate x and Y

 

 

        VAR1

 

x                  /1234/ ()

y                  /4567/ ()

 

 

        VAR1                                           VAR2

 

x                  /1234/ ()                         x

y                  /4567/ ()                          y

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

Your representation of sample data doesn't make sense. Please provide proper sample data.

 

If they are properly delimited then you can use SCAN or SUBSTR functions or if looking for specific words then use FIND or INDEX 

 

data test;
infile datalines ;
input var1 $20.;
datalines;
x /1234/ ()
y /4567/ ()
;
run;

data want;
set test ;
var2=scan(var1,1);/* If they are properly delimited by space*/
run;
Thanks,
Suryakiran
Almoha
Calcite | Level 5
No ,there are not properly spaced.
and can have mutiple () () or {} etc..
andreas_lds
Jade | Level 19

@Almoha wrote:
No ,there are not properly spaced.
and can have mutiple () () or {} etc..

Then, please, be so kind to post example data having the same complexity as your real data.

PeterClemmensen
Tourmaline | Level 20
data have;
input VAR1 $50.;
datalines;
x                  /1234/ ()
y                  /4567/ ()
;

data want;
   set have;
   var2=substr(VAR1,1,1);
run;
Astounding
PROC Star

Even simpler?

 

data want;

set have;

length var2 $ 1;

var2=var1;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1242 views
  • 1 like
  • 5 in conversation