BookmarkSubscribeRSS Feed
SAS_Muggle
Fluorite | Level 6

I want to use the nliteral function to rename a variable into the label, however, I need to parse the label. Is it possible to combine the nliteral with the scan function, or if not is there a workaround? 

2 REPLIES 2
Tom
Super User Tom
Super User

@SAS_Muggle wrote:

I want to use the nliteral function to rename a variable into the label, however, I need to parse the label. Is it possible to combine the nliteral with the scan function, or if not is there a workaround? 


I cannot figure out what you mean.  You only need to apply the NLITERAL() function to the value once you have decided what you want it to be.  Finish all of your "parsing" before you get to the step of generating the new name.

data want;
  set have;
  length new_name $64 ;
  * generate new_name from LABEL ;
  new_name=substr(coalesce(label,name),1,32);
  * Now make it an name literal ;
  new_name = nliteral(new_name);
run;
ballardw
Super User

Please provide an actual example and the desired result.

I am afraid that "rename a variable" in this context is very likely going to be difficult if your label has any length at all. Even with the generally ugly and awkward to use name literals you are still limited to 32 characters for the variable name.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 808 views
  • 0 likes
  • 3 in conversation