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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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