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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
OliviaWright
SAS Employee

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!

View solution in original post

7 REPLIES 7
Reeza
Super User

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. 

West26
Obsidian | Level 7

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.

Reeza
Super User

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. 

West26
Obsidian | Level 7

   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.

OliviaWright
SAS Employee

Hi @West26, where you have "score is null" you should have either "rank="null"" or "rank=." Check out my solution below. 🙂

OliviaWright
SAS Employee

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!

West26
Obsidian | Level 7
Thank you so much. Appreciated.

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
  • 7 replies
  • 15094 views
  • 0 likes
  • 3 in conversation