I want to rename the same three variables across a group of files. Thought %str would work, but it didn't
27 %let ren=%str(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID);
28
27 %let ren=%str(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID);
_
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
29 Data pbp_b1a;
30 set D107342.pbp_b1a (keep=&keepvars pbp_b1a_auth_yn
___
180
ERROR 180-322: Statement is not valid or it is used out of proper order.
31 rename=(
32 %bquote(&ren)
33 pbp_b1a_auth_yn=inpatient_acute_auth
34 ));
35 run;
36
You don't need %str macro function there, there is nothing to mask.
E.g.
%let ren= (age=age_group sex=sex_group height=height_group);
%put &=ren;
data have;
set sashelp.class (rename=&ren);
run;
1 %let ren= (pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID 1 ! segment_id=Segment_ID); 2 3 %put &=ren; REN=(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID) 4 %let ren= (age=age_group sex=sex_group height=height_group); 5 6 %put &=ren; REN=(age=age_group sex=sex_group height=height_group) 7 data have; 8 set sashelp.class (rename=&ren); 9 run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.HAVE has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.03 seconds
I would double check the syntax. As you see in example above equal signs passes into macro var without issue.
You don't need %str macro function there, there is nothing to mask.
E.g.
%let ren= (age=age_group sex=sex_group height=height_group);
%put &=ren;
data have;
set sashelp.class (rename=&ren);
run;
1 %let ren= (pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID 1 ! segment_id=Segment_ID); 2 3 %put &=ren; REN=(pbp_a_hnumber=H_Number pbp_a_plan_identifier=Plan_ID segment_id=Segment_ID) 4 %let ren= (age=age_group sex=sex_group height=height_group); 5 6 %put &=ren; REN=(age=age_group sex=sex_group height=height_group) 7 data have; 8 set sashelp.class (rename=&ren); 9 run; NOTE: There were 19 observations read from the data set SASHELP.CLASS. NOTE: The data set WORK.HAVE has 19 observations and 5 variables. NOTE: DATA statement used (Total process time): real time 0.02 seconds cpu time 0.03 seconds
I would double check the syntax. As you see in example above equal signs passes into macro var without issue.
Missing some bits. For you to get that error on line 27 something else is likely going before line 27 that is making that %let have a problem. Also, please post LOG text into a text box opened on the forum with the </> icon above the main message window. That will have the diagnostic characters, such as the underscore that appears above the 180, in the proper position relative to the code.
Strongly suggest that you show the code submitted before this along with this code.
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 16. Read more here about why you should contribute and what is in it for you!
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.