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-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!

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.

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
  • 721 views
  • 0 likes
  • 3 in conversation