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
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;
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;
@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;
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.
Ready to level-up your skills? Choose your own adventure.