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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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