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
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;
@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.
data have;
input VAR1 $50.;
datalines;
x /1234/ ()
y /4567/ ()
;
data want;
set have;
var2=substr(VAR1,1,1);
run;
Even simpler?
data want;
set have;
length var2 $ 1;
var2=var1;
run;
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!
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.