Skip past navigation to main part of page
 
Melbourne Institute Homepage
---

SAS macro to strip the first letter from the variable name

 

%macro HILDARenameStripFirst(dataset);
/* --------------------------------------------------------------------------
Generates a rename statement of the form
Xvar1=var1 Xvar2=var2 etc
where XvarN includes all variables (except Xwaveid).
Usage example when setting up a long file:
data long2;
set hilda.combined_a (rename=(%HILDARenameStripFirst(hilda.combined_a)) in=in1)
hilda.combined_b (rename=(%HILDARenameStripFirst(hilda.combined_b)) in=in2);
if in1 then Wave=1;
else if in2 then Wave=2;
keep xwaveid hhrhid wave;
run;
proc sort data=long2;by xwaveid wave;run;
Bruce Bradbury Aug07.
Tested on SAS version 9.1.3
I used SAS paper 107-28 by Derek Morgan as inspiration for the sysfunc calls.
----------------------------------------------------------------------------- */
%let DS = %sysfunc(open(&dataset,i)); /* open dataset to get variable names */
%if (&DS = 0) %then %put %sysfunc(sysmsg()); /* if can't open */
%else
%do i=1 %to %sysfunc(attrn(&DS,NVARS));
%let varname = %sysfunc(varname(&DS,&i)); /* get the ith variable name */
%let newvarname = %substr(&varname,2); /* strip off the first character */
%if %upcase(&varname)^=XWAVEID %then %do;
%* output code here;
&varname=&newvarname
%end;
%end;
%let CloseCode = %sysfunc(close(&DS));
%mend HILDARenameStripFirst;

 

top of pagetop of page

HILDA Contact us

Contact the University : Disclaimer & Copyright : Privacy : Accessibility