0
$\begingroup$

The ICT team provides me with a dataset with a column that changes name every month, but always starts with "Reality". It's always column 10. There are other variables that match these condition, but I need the FIRST one to match this condition. But selecting a column by an index seems near impossible in SAS. So I want to rename this variable, so I can access it easier in SAS. I created this macro. But it doesn't work.

The purpose of the code is to rename the first numeric variable in the dataset PetitsPr.mydataFULL that starts with "Reality" to "GotYouMTF".

Any ideas?

%macro Renaming;

data PetitsPr.mydataFULL2;
    set PetitsPr.mydataFULL;

    %local flag; 

    if _n_ = 1 then do;
        %let flag = 0; 
        array vars(*) _numeric_;
        do i = 1 to dim(vars);
            if substr(vname(vars(i)), 1, 7) = "Reality" then do;
                %let flag = 1; 
                call symputx('old_var', vname(vars(i)));
                call symputx('new_var', "GotYouMTF");
                leave;
            end;
        end;
    end;

    rename %sysfunc(quote(&old_var)) = %sysfunc(quote(&new_var)); 

run;

%put Flag: &flag.; 

%mend;
%Renaming();
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.