BookmarkSubscribeRSS Feed
OzoneX15
Calcite | Level 5
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
3 REPLIES 3
Cynthia_sas
Diamond | Level 26
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]
Ksharp
Super User
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
OzoneX15
Calcite | Level 5
Thanks Cynthia and Ksharp.

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

Stefaan

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2186 views
  • 0 likes
  • 3 in conversation