Hi,
I'm getting csv file as input......In that three columns are varying all time.
So, i'm using below code to handle that one.
From those variables i want to pick part of the string.,I'm trying below code
getting error....Can somebody help me how to handle this scenario.
from this variable Pack Units-jun'11 ....i have to pick just jun'11.
Here is error msg:
rename
26 ! &vara1=substr(compress(&vara1),length(&vara1),-5);
_
22
ERROR: Alphabetic prefixes for enumerated variables (PackUnits-jun11) are different.
2 The SAS System 16:18 Tuesday, August 30, 2011
26 (compress(&vara1),length(&vara1),-5);
_
76
ERROR 22-322: Syntax error, expecting one of the following: a name, -, :, ;.
ERROR 76-322: Syntax error, statement will be ignored.
27 run;
Proc contents data = SASUSER.TEST12 out = contents1;
run;
Proc sql;
select distinct name into : vara1-:vara3 from contents1 where name not in ('Account Manager','CORPORATE PARENT NAME')
order by VARNUM;
quit;
data final ;
set SASUSER.TEST12;
rename &vara1=substr(compress(&vara1),length(&vara1),-5);
run;
Thanks,
reddy.
How about:
options validvarname=any; data test; "Pack Units-jun'11"n= 'asdasdf'; run; %let var1= %str(Pack Units-jun%'11) ; proc datasets library=work memtype=data; modify test; rename "%unquote(&var1)"n="%scan(&var1,-1,%str(-))"n; quit; %put _user_;
Ksharp
reddy
with what code do you read the file into SAS?
Whatever it is, that might have an option to create column names that are easier to work with.
Looks like the existing routine is generating column names that conform to option validvarnane= any;
These are awkward to handle in the macro language but simpler in a data step.
like:
data _null_ ;
if _n_ = 1 then call execute(' data final ; set sasuser.test12; rename ' ) ;
set contents end= eof ;
where lowcase(name)=: 'pack units-' ;
length newA1 $32 ;
newA1 = scan( name, -1, '-' ) ; *picking out the suffix after the - ;
call execute( quote(trim(name)) !! 'n = ' !! quote( trim(newA1)) !! 'n' ) ;
if eof ;
call execute( ' ; run ;' ) ;
run ;
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.