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

Hi!

I want to create a variable who goes frome 1 to 12 based on the date of a test (like first test of the year, second test of the year etc) Here is a little example of what I want it to look like:

Annie_Fréchette_0-1594643534926.png

Anyone can teach me?

 

Thanks a lot!

 

Annie

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

please try

 

data have;
input cow$ irtest:ddmmyy10. scc;
cards;
daisy 10/7/2017 200
maggy 10/7/2017 120
lily 10/7/2017 98
daisy 11/8/2017 89
maggy 11/8/2017 120
lily 11/8/2017 98
;

proc sort data=have;
format irtest date9.;
by cow irtest;
run;

data want;
set have;
by cow irtest;
retain no_test;
if first.cow then no_test=1;
else no_test+1;
run;
Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

please try

 

data have;
input cow$ irtest:ddmmyy10. scc;
cards;
daisy 10/7/2017 200
maggy 10/7/2017 120
lily 10/7/2017 98
daisy 11/8/2017 89
maggy 11/8/2017 120
lily 11/8/2017 98
;

proc sort data=have;
format irtest date9.;
by cow irtest;
run;

data want;
set have;
by cow irtest;
retain no_test;
if first.cow then no_test=1;
else no_test+1;
run;
Thanks,
Jag
Annie_Fréchette
Obsidian | Level 7

Thank you very much!

andreas_lds
Jade | Level 19

Can be solved by sorting data by Cow and JR_Test and a datastep with first and retain to create no_test.

data want;
  set have_sorted;
  by Cow;

  length no_test 8;
  retain no_test;

  if first.Cow then no_test = 0;
  no_test = no_test + 1;
run;

The code is untested, because you haven't provided data in usable form.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 528 views
  • 2 likes
  • 3 in conversation