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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Tom
Super User Tom
Super User

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. 

alexdsa310
Obsidian | Level 7

Thanks tom.

 

I i use your solution i get the following note

NOTE: Invalid numeric data for that variable

alexdsa310
Obsidian | Level 7

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;

Tom
Super User Tom
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 2222 views
  • 0 likes
  • 2 in conversation