BookmarkSubscribeRSS Feed
reddy19
Calcite | Level 5

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.

2 REPLIES 2
Ksharp
Super User

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

Peter_C
Rhodochrosite | Level 12

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 ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 4135 views
  • 0 likes
  • 3 in conversation