« SAS coding fun - another solution | Main | Match Merge using Proc SQL »

SAS coding fun

I like keeping snippets of easy to read datastep programming because I find it helps me learn.  Soere is some code that uses the retain statement and the proc sorts built-in variable of first.variable. I also like this code because it uses a date variable - something I haven't used much in my current work.

If you are a n00b to SAS programming, run this and look at the resulting datasets.  You should learn a thing or two. 

data practice_dates;
  input id date mmddyy8. test passed $;
  format date mmddyy10.;
  datalines;
1234 01021969 2345 Y
1234 01301969 3456 N
3157 02031969 2345 N
3157 02201969 2897 N
3157 04151969 2345 Y
1011 02051969 2345 N
1011 02211969 2345 N
1011 05201969 2897 N
2468 03211969 2234 Y
2468 07151969 2255 Y
;

proc sort data=practice_dates;
  by id descending passed;
run;

data want;
  set practice_dates;
  retain passed_test;
  by id;
  if first.id then do;
    if passed eq 'Y' then passed_test=1;
    else passed_test=0;
  end;
  if passed_test then output;
run; 

Posted on Wednesday, June 4, 2008 by Registered CommenterJared in | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>