Hi Guys, I want to create a loop, to get the value of date in the entire pre-defined year. For example, if i pre-define 2018, in the output, i want to get 20180101 until 20181231. So if i pre-define 2019, i will get the output result set of 20190101 until 20191231
Then later I will use the result sets to further process my other data. May i know if there is a function to achieve the task?
Since SAS date values are counts of days, this can easily be achieved in a do loop:
%let year=2019;
data want;
do mydate = mdy(1,1,&year) to mdy(12,31,&year);
/* your code */
end;
format mydate yymmddn8.;
run;
hi , you can do it using a do loop also , please refer the below code
data dat;
_date=mdy(1,1,&year);
output;
do until (_date=mdy(12,31,&year));
_date+1;
output;
end;
format _date date9.;
run;
Not sure how you want to use it, but the year function may be all that you need. e.g.:
data have; input date date9.; format date date9.; cards; 10jan2017 5mar2018 10jun2018 14may2019 ; data want; set have (where=(year(date) eq 2018)); run;
Art, CEO, AnalystFinder.com
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.