BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
gfdan3011
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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;

View solution in original post

4 REPLIES 4
Patrick
Opal | Level 21

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;
gfdan3011
Fluorite | Level 6

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! 

ChrisBrooks
Ammonite | Level 13

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...

gfdan3011
Fluorite | Level 6

Thank you Chris! You were right! I really appreciate the web link too! 

 

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
  • 4 replies
  • 1929 views
  • 2 likes
  • 3 in conversation