BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ranjeeta
Pyrite | Level 9
data test;
   input fyear $ inst $  unit;
   datalines;
2013 1030 0
2014 1030 1
2015 1030 1 ;

For the above dataset 

 

Also would appreciate if you can advise how would I identify in which Fiscal year a particular institution started to have the value of 1

 

I have a dataset as follows

FY           INST         HAS STROKEUNIT

2013      1030           0

2014       1030         1

2015      1030          1

 

 

I need the result that inst 1030 started to have the value of 1 in FY 2014

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Here two possible options.

data have;
   input fyear $ inst $  unit;
   datalines;
2013 1030 0
2014 1030 1
2015 1030 1
;

/* option 1 */
proc sort data=have out=inter;
  by inst unit fyear;
run;

data want1;
  set inter;
  by inst unit fyear;
  if first.unit and unit=1 then output;
run;

/* option 2 */
proc sql;
  create table want2 as
  select *
  from have
  where unit=1
  group by inst
  having fyear=min(fyear)
  ;
quit;

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

Here two possible options.

data have;
   input fyear $ inst $  unit;
   datalines;
2013 1030 0
2014 1030 1
2015 1030 1
;

/* option 1 */
proc sort data=have out=inter;
  by inst unit fyear;
run;

data want1;
  set inter;
  by inst unit fyear;
  if first.unit and unit=1 then output;
run;

/* option 2 */
proc sql;
  create table want2 as
  select *
  from have
  where unit=1
  group by inst
  having fyear=min(fyear)
  ;
quit;
ballardw
Super User

@Ranjeeta wrote:
data test;
   input fyear $ inst $  unit;
   datalines;
2013 1030 0
2014 1030 1
2015 1030 1 ;

For the above dataset 

 

Also would appreciate if you can advise how would I identify in which Fiscal year a particular institution started to have the value of 1

 

I have a dataset as follows

FY           INST         HAS STROKEUNIT

2013      1030           0

2014       1030         1

2015      1030          1

 

 

I need the result that inst 1030 started to have the value of 1 in FY 2014


Any particular reason that FYEAR is character? Since many manipulations of date values involve the numeric values I find it a tad odd.

If numeric another way would be :

data test;
   input fyear inst $  unit;
   datalines;
2013 1030 0
2014 1030 1
2015 1030 1
;

proc summary data=test nway;
   where unit=1;
   class inst;
   var fyear;
   output out=want (drop=_:) min=;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 728 views
  • 0 likes
  • 3 in conversation