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

Hi! Thanks in advance for your help!

I have two data sets(Base and Sheet1). They have a common key, let's say "ID". I want to create a "flag" = 1 in Sheet1 if ID from Sheet1 is shown in Base and flag = 0 otherwise. I did this following the code below:

data temp1; 
	if _N_ = 1 then do;
		declare hash VET(dataset: 'Base');
		VET.definekey('org');
		VET.definedone();
	end;
	set Sheet1;
	FLAG = VET.check();
run;

This works perfectly fast. However, I have many "Sheet1", let's say Shee1 - Sheet300 (I ran a macro to read those 300 files to the library.work). I want to perform the same procedure on them. So I wrote a macro:

%macro csv(howmany);
%do i = 1 %to &howmany;
data temp&i;
	%if _N_ = 1 %then %do;
	declare hash VET(dataset: 'Base');
	VET.definekey('org');
	VET.definedone();
	%end;
	set Sheet&i;
	FLAG = VET.check('org');
run;
%end;
%mend csv;

Then I ran into an error. It says:

ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.
ERROR 557-185: Variable VET is not an object.

 

Can anyone help?

 

After this step, I want to stack/append (proc append) those observations with Flag =1. I imagine this will take much of the space since we read them in and store them. Any more efficient way?

 

 

 

 

 

Thanks,

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Don't convert your DATA step DO loop:

%macro csv(howmany);
%do i = 1 %to &howmany;
data temp&i;
	if _N_ = 1 then do;
	declare hash VET(dataset: 'Base');
	VET.definekey('org');
	VET.definedone();
	end;
	set Sheet&i;
	FLAG = VET.check('org');
run;
%end;
%mend csv;

 

View solution in original post

1 REPLY 1
SASKiwi
PROC Star

Don't convert your DATA step DO loop:

%macro csv(howmany);
%do i = 1 %to &howmany;
data temp&i;
	if _N_ = 1 then do;
	declare hash VET(dataset: 'Base');
	VET.definekey('org');
	VET.definedone();
	end;
	set Sheet&i;
	FLAG = VET.check('org');
run;
%end;
%mend csv;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 705 views
  • 1 like
  • 2 in conversation