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
SAS Super FREQ
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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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