I am just a very beginner SAS programmer. I am trying to do the following inside a data step:
data work.gifts;
set orion.nonsales;
length Gift1 $7 Gift2 $10;
Gift1=select (Gender) when ('M') 'gloves'
when ('F') 'scarves'
otherwise 'caffee'
end;
run;
However I am getting this error:
ERROR 68-185: The function SELECT is unknown
Gender is a variable included already in the nonsales table and Gift1 and Gift2 are two new variables that I am trying to conditionally initialize based on the value in the variable Gender.
Any help would be really appreciated! Thank you!
SELECT in the Base SAS language is a statement and not a function. You can only use functions on the right side of an equal sign.
Using the SELECT statement your code could look as follows (untested):
data work.gifts;
set orion.nonsales;
length Gift1 $7 Gift2 $10;
select(gender);
when('M') gift1='gloves';
when('F') gift1='scarves';
otherwise 'coffee';
end;
run;
SELECT in the Base SAS language is a statement and not a function. You can only use functions on the right side of an equal sign.
Using the SELECT statement your code could look as follows (untested):
data work.gifts;
set orion.nonsales;
length Gift1 $7 Gift2 $10;
select(gender);
when('M') gift1='gloves';
when('F') gift1='scarves';
otherwise 'coffee';
end;
run;
Thank you so much Patrick! It did work!
I was trying to find that wrong example that I used as an inspiration but without success. If I will find it, I will post it and let SAS know about it.
Also, I apologize for my late reply! I had to prepare for a couple of interviews.
Thank you again!
Your syntax is slightly wrong - you're using SELECT as a function when it's a statement.
There are some examples of correct usage and documentation here -> http://support.sas.com/documentation/cdl/en/lestmtsref/68024/HTML/default/viewer.htm#p09213s9jc2t99n...
Thank you Chris! You were right! I really appreciate the web link too!
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.