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?
@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;
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.
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!
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.