I am running a lot of variables through a macro which is using the variable name to create temp dataset names. Some of my var names are too long resulting in an error when the macro can't create the dataset (too many characters). Is there an easy way to count how many characters are in my variable names so I can identify any that are longer than 25 characters in order to rename them prior to running them through the macro? I don't need help in renaming them - I just want the count of characters in each variable name. I have about 100 variables to check in total so it would be helpful to not do this manually if possible.
Examples variable names are:
Idx1base_Azole_antifungals
mon_all_chemo_supp_std_cost1
and macro wants to use the var name like this:
data chisq_&var.;
etc.
Thank you!
One way:
proc sql;
select name
from sashelp.vcolumn
where libname="SASHELP" and memname="CARS" and length(name)>10;
quit;
If you have a macro variable named VAR you can use the %LENGTH() macro function to find out how long it is.
%if %length(&var) > 25 %then %do;
%put Variable name &VAR is too long.
%end;
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.
Ready to level-up your skills? Choose your own adventure.