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

Hi ,

 

I am trying to use has as a look up table to join two tables. My issues is i will get data from the source table only once in four days. For other days the table will have zero records. Because of this reason I am not able use this code since my macro count variables wont be created for data set with zero records since the logic wont enter the do until loop. Can u help me with a logic so that i can join the tables if the data exists or create a macro variable with zero as count if the source key dataset is empty

 

data work.sasgrid_extract(drop= rc tot_cnt);
set work.source_key_extract ;

declare hash stac (dataset: 'work.source_key_extract');
stac.definekey('acct');
stac.definedone();
do until(eof);
set vp.account_table (keep = acct
amount
type
code
flag
date

) end=eof ;
rc = stac.find();
if rc eq 0 then do;
sas_acct = acct;
tot_cnt+1;
output;
end;
call symputx("sas_stac_cnt",tot_cnt);
end;
stop;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Just code your step so that it does try to read past the end of the input dataset.

It looks like you are not really using that first SET statement to read the data (that is being done later) so make it impossible to execute.

if 0 then set work.source_key_extract ;

and then SAS will not try to read past the end when it is empty.

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Just code your step so that it does try to read past the end of the input dataset.

It looks like you are not really using that first SET statement to read the data (that is being done later) so make it impossible to execute.

if 0 then set work.source_key_extract ;

and then SAS will not try to read past the end when it is empty.

ChrisNZ
Tourmaline | Level 20

create a macro variable with zero as count if the source key dataset is empty

Just add

    call symput('sas_stac_cnt','0');

before the SET statement.

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
  • 2 replies
  • 929 views
  • 0 likes
  • 3 in conversation