Have a dataset with three columns
have dataset
dob1 dob2 rank
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 2
needed dataset
dob1 dob2 rank
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 null
if dob1=dob2 then ran=null ; else rank=rank;
both dob1 and dbo2 are date formats (type=date and length 😎
Please help how to get needed dataset. Thanks
Hi @West26!
If your "rank" variable is categorical, you can do what your describing with the code below:
data have;
input @1 dob1 mmddyy10. @12 dob2 mmddyy10. @23 rank $;
datalines;
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 2
;
run;
data need;
set have;
if dob1=dob2 then rank ="null";
run;
If your "rank" variable is numeric, and by "null" you mean you want the entry to be missing, you can use the following code:
data have;
input @1 dob1 mmddyy10. @12 dob2 mmddyy10. @23 rank;
datalines;
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 2
;
run;
data need;
set have;
if dob1=dob2 then rank =.;
run;
Hope that helps!
Did you try the code you've shown? If it didn't work, please explain how.
You've misspelled rank and you specify null in SAS with the period ( . ) or use CALL MISSING instead.
Hi Reeza,
Thanks for taking your time to reply my post.
Getting the below error.
Statement is not valid or it is used out of proper order.
Haven't misspelled rank, while I'm coding. Sorry it's a typo mistake in the post.
But my doubt is can we use dob1=dbo2?
As dob1 doesn't have a value of dob2, I don't think it is proper syntax.
So, definitely it's a syntax error. And I need to know what would be the right one.
Thanks again.
Post your code and log.
You're stating there's errors but we can't see them or your data or your code so it's a guessing game, which I don't really want to play.
Good Luck.
dob1 dob2 rank
10/18/2017 01/27/1998 1
10/09/2017 11/03/1982 3
08/23/2017 04/09/1999 1
10/23/2017 05/20/1988 2
10/18/2017 07/12/1999 1
09/25/2017 09/25/2017 1
09/25/2017 09/25/2017 1
09/26/2017 09/26/2017 3
Log
data get;
set have;
if dofb eq dob1 then score is null;
else rank=rank;
run;
Log
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: The SAS System stopped processing this step because of errors.
Hi @West26, where you have "score is null" you should have either "rank="null"" or "rank=." Check out my solution below. 🙂
Hi @West26!
If your "rank" variable is categorical, you can do what your describing with the code below:
data have;
input @1 dob1 mmddyy10. @12 dob2 mmddyy10. @23 rank $;
datalines;
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 2
;
run;
data need;
set have;
if dob1=dob2 then rank ="null";
run;
If your "rank" variable is numeric, and by "null" you mean you want the entry to be missing, you can use the following code:
data have;
input @1 dob1 mmddyy10. @12 dob2 mmddyy10. @23 rank;
datalines;
10/18/2017 10/27/1998 1
10/09/2017 11/03/1982 2
09/10/1991 09/10/1991 2
;
run;
data need;
set have;
if dob1=dob2 then rank =.;
run;
Hope that helps!
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.
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.