BookmarkSubscribeRSS Feed
efarrelly
Calcite | Level 5

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!

2 REPLIES 2
PGStats
Opal | Level 21

One way:

 

proc sql;
select name
from sashelp.vcolumn
where libname="SASHELP" and memname="CARS" and length(name)>10;
quit;
PG
Tom
Super User Tom
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 702 views
  • 0 likes
  • 3 in conversation