Creating a conditional Variable

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Creating a conditional Variable

This dataset contains three variables (city, id, test, date).  I want to create a new variable "visnum" based on the date.  Each id completed the same five tests on two different dates.  visnum will be assigned two values (1 or 2).  Attached is an excel spreadshet of what I have vs. what I want.  How to I code for "visnum"?  Please let me know if there is more information that is needed.  Thank you.


Accepted Solutions
Solution
‎09-01-2016 02:20 AM
Respected Advisor
Posts: 4,826

Re: Creating a conditional Variable

Proc rank will do the job, given proper ordering:

 

proc sort data=have; by city id test date; run;

proc rank data=have out=want;
by city id test;
var date;
ranks visnum;
run;

proc sort data=want; by city id date test; run;
PG

View solution in original post


All Replies
Solution
‎09-01-2016 02:20 AM
Respected Advisor
Posts: 4,826

Re: Creating a conditional Variable

Proc rank will do the job, given proper ordering:

 

proc sort data=have; by city id test date; run;

proc rank data=have out=want;
by city id test;
var date;
ranks visnum;
run;

proc sort data=want; by city id date test; run;
PG
☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 404 views
  • 1 like
  • 2 in conversation