Hi;
I've been asked to write some code which will deal with date variables and date ranges within a dataset (in SAS 9,3.)
The specification details that the code should be able to handle an unknown number of date variables (in ddmmyy10. format) , with unspecified names. It should also remove any dates in a variable if they fall outside of a specified range...... if a range is specified that is.
My thought was to create a csv parameter file that could be imported in, specifying the names of any variables, and a start and end date if needed.
So, i imported the file:
data test;
infile date dsd dlm='2c'x;
informat name $32. start ddmmyy10. stop ddmmyy10.;
input name start stop;
format start stop ddmmyy10.;
run;
(eg of file contents:
one_date 01/01/1990 12/12/1999
another_date . .
)
then created macro variables for each column:
proc sql;
select name into: date_vars separated by " " from test;
select start into: start separated by " " from test;
select stop into: stop separated by " " from test;
quit;
from here, my first thought was a simple if then statement:
data want;
set have;
if &start ne . then if date_vars le &start then &date_vars = .;
run;
Which falls over with
NOTE: Line generated by the macro variable "START".
1 01/01/1990 .
-
22
as well as syntax errors.
I also tried arrays, which ended up with similar problems as well as "too many subscripts....." messages.:
array datevars{*} &date_vars ;
array startdates{*} &start ;
do i = 1 to dim(datevars);
do j = 1 to dim2(startdates);
if startdates{j} ne '.' then
if (datevars{i} le startdates{j}) then datevars{i} = ' ';
end;
run;
I realise I must have made some very rookie errors, but any pointers as to where I am going wrong (probably all of it... 🐵 )or any other help to accomplish this would be greatly appreciated! 🐵
Many Thanks in advance
... View more