Help using Base SAS procedures

Generate a sequence of observations

Reply
Occasional Contributor
Posts: 14

Generate a sequence of observations

Hi all,

I have a dataset with 5 observations;

OBSERVATION

F
T
J
D
D



I want to spread the observations like this (so the first obervation has to be there for the first five days, the second observations has to be there for the next five days, (from day 6 to 10,... and so on);

I want to come up with the following dataset;

DAY,OBSERVATION
1,F
2,F
3,F
4,F
5,F
6,T
7,T
8,T
9,T
10,T
11,J
12,J
13,J
14,J
15,J
16,D
17,D
18,D
19,D
20,D
21,D
22,D
23,D
24,D
25,D


I have programmed this in the following way,

options nomprint nosymbolgen nomlogic;
%macro result;

data %do i=1 %to 5;

Data VECTOR_PRE (drop=obsnum);
obsnum=&i;
set VECTOR_ point=obsnum;
output;
stop;
run;

DATA OUTPUT&i;
SET VECTOR_PRE;
day=0;
do day=&i*(30)-30+1 to &i*(30);
output;
end;
run;

%end;


data sasuser.want;
set output: indsname=dsn;
drop dsn;
run;
%mend ;
%result


Is there a way to do this in a datastep, so without using a macro?

Kind regards,

Stefaan Message was edited by: OzoneX15
SAS Super FREQ
Posts: 8,743

Re: Generate a sequence of observations

Hi:
It may be that a macro solution is too much programming for what you need.

cynthia
[pre]
data genobs;
infile datalines;
drop i;
retain day 0;
input @1 obsval $;
do i = 1 to 5 by 1;
day + 1;
output;
end;
datalines;
F
T
J
D
D
;
run;

proc print data=genobs noobs;
run;
[/pre]
Super User
Posts: 9,687

Re: Generate a sequence of observations

Hi.Sorry so late to reponse.
How about this:
[pre]


data temp;
input obs $;
datalines;
F
T
J
D
D
;
run;
data want(drop=i);
set temp;
do i=1 to 5;
day+1; output;
end;
run;

[/pre]

My code I send you this morning is worked?

Thanks
Ksharp
Occasional Contributor
Posts: 14

Re: Generate a sequence of observations

Thanks Cynthia and Ksharp.

@ Ksharp: Yes the code works perfectly. I've learned to work with arrays now...
but still need to practice:-)

Stefaan
Ask a Question
Discussion stats
  • 3 replies
  • 408 views
  • 0 likes
  • 3 in conversation