I'm sure there's a simple solution to this problem, but I'm a new enough user so here goes. I'm using SAS enterprise guide. I have a dataset like so
var1 date
1.1 Feb2018
1.4 Mar2018
2.6 Apr2018
3.3 May2018
4.5 Jun2018
and I would like to create a column that repeats the earliest var1 value, like so
var1 date base
1.1 Feb2018 1.1
1.4 Mar2018 1.1
2.6 Apr2018 1.1
3.3 May2018 1.1
4.5 Jun2018 1.1
Not sure if I should use proc sql or a data step here. Thanks in advance
Assuming the data is sorted by var, you should be able to use a retain statement?
For example:
data temp;
set vardate;
retain base;
if _N_ = 1 then base = var;
run;
You can expand this to grouped data (for example if you had another column ahead) using "BY" and "first." statement.
Assuming the data is sorted by var, you should be able to use a retain statement?
For example:
data temp;
set vardate;
retain base;
if _N_ = 1 then base = var;
run;
You can expand this to grouped data (for example if you had another column ahead) using "BY" and "first." statement.
data have;
input var1 date : anydtdte7.;
format date monyy7.;
cards;
1.1 Feb2018
1.4 Mar2018
2.6 Apr2018
3.3 May2018
4.5 Jun2018
;
proc sql;
create table want as
select *,(select var1 from have having date=min(date)) as base
from have;
quit;
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: