I need to merge two data sets, but one of them has one thing labelled two ways: "Place A" and "Place_A". I want to keep it as "Place A" Because I am plotting this data later on and the _ is not a beautiful thing.
Then, I need to merge the data sets based on place, but that is not the issue here, I am trying to replace "Place_A" with "Place A" in one data set so when I merge, they are recognized as the same variable. Code:
data test2;
set test;
if PLACE = Place_A then PLACE = 'Place A'n;
run;
Error: "Place A is not a valid SAS name".
This is in SAS 9.2 Unix.
I assume you have a variable named PLACE in your input and you want to replace '_' with ' ' then
either do:
place = translate(place,' ','_'); /* arguments: variable name, replacement, to be replaced */
or correct your code using literals to distinguish from variables:
if place = 'Place_A' then place = 'Place A';
in this case you can use either single quotes or double quotes.
I assume you have a variable named PLACE in your input and you want to replace '_' with ' ' then
either do:
place = translate(place,' ','_'); /* arguments: variable name, replacement, to be replaced */
or correct your code using literals to distinguish from variables:
if place = 'Place_A' then place = 'Place A';
in this case you can use either single quotes or double quotes.
Just to clarify, I have a variable named PLACE and it has some of its values named Place_A that I want to change to Place A
Thank you, I added VALIDVARNAME = ANY in the data statement and it told me that it created a data set with 0 observations.
data test VALIDVARNAME = ANY;
set test2;
if PLACE = Place_A then PLACE = 'Place A'n;
run;
or:
data test;
set test2;
VALIDVARNAME = ANY
if PLACE = Place_A then PLACE = 'Place A'n;
run;
You are mixing variable name with variable value.
Is 'Place_A' a variable name ? If YES maybe you want to add
LABEL Place_A = 'Place A';
then define you prefer use lables in the chart/report instead variable names.
Otherwise - see my previous post.
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.