DATA Step, Macro, Functions and more

how to code all variable names with different suffix in "IF" statement

Reply
New Contributor
Posts: 3

how to code all variable names with different suffix in "IF" statement

I have character variables, abscode_1, abscode_2, ..., abscode_8. I'm going to use "if & else" statement in SAS to create a new variable by selecting all the variables.

Here's my question.

I am going to assign a new variable as missing if all the variables are missing. But I don't know how to code this.

I would appreciate your help.

    

 

Respected Advisor
Posts: 4,934

Re: how to code all variable names with different suffix in "IF" statement

Posted in reply to peachblozzom

Assuming abscode_i are numeric :

if n(of abscode_Smiley Happy = 0 then call missing (new_variable);

PG

PG
Contributor
Posts: 60

Re: how to code all variable names with different suffix in "IF" statement

Additional information to PGSTATS reply.

n() ==> will count the no of non-missing values in all the variable listed

Call missing will assign missing values to numeric or character variable which is listed in () so we need to decide the new variable typebefore using it in the function. or you can give it as New_variable=.;

Ask a Question
Discussion stats
  • 2 replies
  • 163 views
  • 1 like
  • 3 in conversation