BookmarkSubscribeRSS Feed
Jaheuk
Obsidian | Level 7
why does my final output dataset has only 2 rows and not 6 (for each date a prod line)?

data dates;
input date $ ;
cards;
01/02/2010
02/02/2010
03/02/2010
;
run;
data prods;
input prod $ ;
cards;
PRODA
PRODB
;
run;

data prods_dates;
set dates;
do order=1 to LAST;
set prods nobs=LAST;
output;
end;
RUN;
3 REPLIES 3
deleted_user
Not applicable
hello,

your final output has only 2 rows because SAS reads sequentially which determines the end of prods file to be "achieved" on the first pass to the data step.

you expected on the second pass to the data step that SAS reads the prods file from the beginning, but instead SAS stops execution and this is because SAS reached the end of prods file.

one solution is using direct access to read the prods file:

[pre]
data prods_dates;
set dates;
i=1;
do order=1 to LAST;
set prods point=i nobs=LAST ;
output;
i+1;
end;
RUN;
[/pre]

Marius
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The SAS variable LAST is incremented until it reaches the NOBS= value (based on WORK.PRODS). Then, unless you were to reset the value to LAST=0; outside your DO /END loop, the "expression" condition will never be met again.

For self-diagnosis, suggest you add the following statement at various points in your SAS program to display all SAS variable values:

PUTLOG '>DIAG>' / _ALL_;

Scott Barry
SBBWorks, Inc.
Jaheuk
Obsidian | Level 7
Marius, thx for solution and reason why it did not work 😉

CU,
Herman

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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