DATA Step, Macro, Functions and more

Select group statement error.

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Select group statement error.

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!


Accepted Solutions
Solution
‎10-25-2015 10:27 PM
Respected Advisor
Posts: 3,902

Re: Select group statement error.

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


All Replies
Solution
‎10-25-2015 10:27 PM
Respected Advisor
Posts: 3,902

Re: Select group statement error.

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;
New Contributor
Posts: 3

Re: Select group statement error.

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! 

Regular Contributor
Posts: 190

Re: Select group statement error.

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

New Contributor
Posts: 3

Re: Select group statement error.

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

 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 219 views
  • 2 likes
  • 3 in conversation