BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PROCDATARUN
Obsidian | Level 7

Thanks a ton to @RichardDeVen  for helping with the set up of code.

 

Am running into the following error for the below code, any help is appreciated.

 

More Background Here 

 

Statement is not valid or it is used out of proper order.

**CODEBELOW*******

data have;
input
Order: $4. Set: $4. Track: $7. SubGroup: $1.;
datalines;
O123 J001 456Y A
O123 J001 456Y B
O123 J001 456Y C
O123 J001 3284G A
O123 J001 3284G B
O123 J001 5657G A
O123 J001 490456B B
O123 J001 490456C C
O123 J001 490456D A
O123 J001 490E B
O123 J001 490F A
O123 J001 490G B
O123 J001 490H C
O123 J001 490I A
O123 J001 490J B
O123 J002 456Y A
O123 J002 456Y B
O123 J002 456Y C
O123 J002 3284G A
O123 J002 3284G B
O123 J002 5657G A
O123 J002 490456B B
O123 J002 490456C C
O123 J002 490456D A
O123 J002 490E B
O123 J002 490F A
O123 J002 490G B
O123 J002 490H C
O123 J002 490I A
O123 J002 490J B
O346 J001 456Y A
O346 J001 456Y B
O346 J001 456Y C
O346 J001 3284G A
O346 J001 3284G B
;
data want;
set have;
by order set;

attrib
Page format=4.
;

if _n_ = 1 then do;
FromSet = Set;
declare hash tracks();
tracks.defineKey('Track');
tracks.defineData('Page');
tracks.defineData('FromSet');
tracks.defineDone();
end;

if first.order then
tracks.Clear();

if first.set then
seq_TrackInSet = 0;

if tracks.find() ne 0 then do; /* new track in set */
seq_TrackInSet + 1;
if seq_TrackInSet <= 10 then do;
Page = seq_TrackInSet;
FromSet = Set;
tracks.add();
end;
end;

* for edification, flag the wanted row;
if tracks.num_items <= 100 and 1 <= seq_TrackInSet <= 10 and Set=FromSet then want_row = '*';

if want_row = '*'; *subsetting if;

drop want_row seq_TrackInSet;

1 ACCEPTED SOLUTION

Accepted Solutions
mklangley
Lapis Lazuli | Level 10

Try adding

run;

at the end.

 

And for consistency, also add it after your input data (before DATA WANT;). It is used to close out each datastep.

View solution in original post

1 REPLY 1
mklangley
Lapis Lazuli | Level 10

Try adding

run;

at the end.

 

And for consistency, also add it after your input data (before DATA WANT;). It is used to close out each datastep.

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
  • 1 reply
  • 772 views
  • 0 likes
  • 2 in conversation