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;

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