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! 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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