Hi ,
I have a variable called xy = 000499 19
and i want to create var1 = 000499 and var2 = 19
can anyone pls let me know how to achieve
Hello,
data want;
xy='000499 19';
var1=scan(xy,1);
var2=scan(xy,2);
run;
hi ,
we have to extract first 6 characters for var1 and next 2 characters for var2
i have used
LEFT(xx,6) as Var1,
RIGHT(LEFT(xx,9),2) as Var2,
but it didnt work i dont know y ?
data want;
xy='000499 19';
var1=substr(xy,1,6);
var2=substr(xy,8,2);
run;
Hi ,
I got it but how is that similar to the left and right function which i have sent you can u pls explain because i have many similar cases where i have to use it
Hello,
Left and Right are used in SAS just to align a character string. Probably you took them from excel where indeed they are used to extract from a string.
Hi ,
Thank you . But can i make left and right function work in SAS to achieve what i need because i have 10 codes to change and also its not same case with everything for example when we have a condition like
xx= NA630011 what is a similar function achieved by below code
LEFT(xx) as Var1,
RIGHT(LEFT(xx),1) as Var2,
RIGHT(LEFT(xx),3) as Var3,
RIGHT(LEFT(xx),3) as Var4,
Thanks
@chennupriya wrote:
xx= NA630011 what is a similar function achieved by below code
LEFT(xx) as Var1,
RIGHT(LEFT(xx),1) as Var2,
RIGHT(LEFT(xx),3) as Var3,
RIGHT(LEFT(xx),3) as Var4,
What would you expect the values of Var1, Var2, Var3 and Var4 to be? I'm not going to guess where you got the example syntax from.
Note: if any of these are single values of 0 or 1 you better point out which 0 and which 1 from the original string contributed it as there would be different ways to get those.
The issue you are having is that you never read the SAS documentation for the LEFT and RIGHT functions. In some other languages, you may be permitted two arguments to these functions. But in SAS, only one argument is permitted. You'll need to read the SAS documentation.
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.
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.