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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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