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 ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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