DATA Step, Macro, Functions and more

how to use multiple variable names in a strip condition

Accepted Solution Solved
Reply
Contributor
Posts: 41
Accepted Solution

how to use multiple variable names in a strip condition

[ Edited ]

i am using the below condition and want to make it standard. but for some sstudies the variable name "aeacn" is "aacn". is there any way where i can make sure that if it is aacn then also it needs to consider. 

data inc;
 set adae;
 if strip(aeacn)="" and strip(withdraw)="" then aeact_use=""; 
 else if aecontrt="N" and strip(upcase(aeacn)) in ("", "NA", "DOSE NO CHANGED") then aeact_use="0";
 else do;
   if aecontrt="Y" then aeact_use="1";
   if strip(upcase(aeacn)) not in ("", "NOT APPLICABLE", "DOSE NOT CHANGED", "DOSE NO CHANGED") then do;
     if aeact_use="" then aeact_use="8";
   end; 
run;

Accepted Solutions
Solution
‎05-16-2017 09:32 AM
Super User
Super User
Posts: 7,043

Re: how to use multiple variable names in a strip condition

Posted in reply to alexdsa310

Sorry. Unlike in SQL in a data step SAS uses different functions for character and numeric values. 

You will need to use the coalesceC() function.

View solution in original post


All Replies
Super User
Super User
Posts: 7,043

Re: how to use multiple variable names in a strip condition

[ Edited ]
Posted in reply to alexdsa310

Your code seems to be missing an END.

 

I think your question is related to having inconsistent input data structures?

If so then just add code to make the data consistent and then run the same logic.

So if your code references variable A and your input could have A or B then add something like this:

length A B $30 ;
A=coalesce(A,B);

That way A is always defined and wil have the first non missing value between the two variables. 

Contributor
Posts: 41

Re: how to use multiple variable names in a strip condition

Thanks tom.

 

I i use your solution i get the following note

NOTE: Invalid numeric data for that variable

Contributor
Posts: 41

Re: how to use multiple variable names in a strip condition

Posted in reply to alexdsa310

sorry code which i modified

data inc;
set adae;
length aeacn aacn $30 ;
aeacn=coalesce(aeacn,aacn);
if strip(aecontrt)="" and strip(aeacn)="" and strip(withdraw)="" then aeact_use="";
else if aecontrt="N" and strip(upcase(aeacn)) in ("", "NOT APPLICABLE", "DOSE NOT CHANGED", "DOSE NO CHANGED") and withdraw="N" then aeact_use="0";
else do;
if aecontrt="Y" then aeact_use="1";
if strip(upcase(aeacn)) not in ("", "NOT APPLICABLE", "DOSE NOT CHANGED", "DOSE NO CHANGED") then do;
if aeact_use="" then aeact_use="2";
else aeact_use=strip(aeact_use)||",2";
end;
if withdraw="Y" then do;
if aeact_use="" then aeact_use="3";
else aeact_use=strip(aeact_use)||",3";
end;
end;
run;

Solution
‎05-16-2017 09:32 AM
Super User
Super User
Posts: 7,043

Re: how to use multiple variable names in a strip condition

Posted in reply to alexdsa310

Sorry. Unlike in SQL in a data step SAS uses different functions for character and numeric values. 

You will need to use the coalesceC() function.

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 166 views
  • 0 likes
  • 2 in conversation