I am trying to create a SAS dataset that looks like the following
I am attempting to use array and a do loop to accomplish this via the following code
DATA dat; array new(20) X1-X20; Do i = 1 to 20; new[i] = new[i] + 1; output; end; RUN;
This code gets me close to the desired dataframe. That is, the position of the missing values are correct however it populates the dataset with all 1s (see below for output). I am not sure what I am doing wrong. I don't understand why new[i[ = new[i] + 1 doesn't increment.
Below should return what you're after.
data dat;
array new(20) x1-x20;
do i = 1 to dim(new);
do k=1 to i;
new[k]=sum(new[k],1);
end;
output;
end;
run;
Below should return what you're after.
data dat;
array new(20) x1-x20;
do i = 1 to dim(new);
do k=1 to i;
new[k]=sum(new[k],1);
end;
output;
end;
run;
/*It is IML thing.*/
proc iml;
have=t(1:20);
want=lag(have,0:19);
create want from want[c=('x1':'x20')];
append from want;
close;
quit;
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!
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.