BookmarkSubscribeRSS Feed
Cincy
Fluorite | Level 6

Hello to SAS professionals,

 

I'm running a code below, which is shared by my professor. However, the error 180-322 keeps showing after I run the macros, and I cannot find where I did wrong.

 

The coding within "StkRun" runs without problem.

 

Thank you a lot!

 

data time;
length ymd $8.;
infile "D:\Schedule\Finance 2022\projects\DtaqTxt\DtaqDays.txt" recfm=v;
input ymd;
if _n_=3 then stop;
run;

*read tics;
data sym;
length stk $10.;
infile "D:\Schedule\Finance 2022\projects\DtaqTxt\StkLst.txt" recfm=v;
input stk mrnk;
if _n_=3 then stop;
run;

*set stock macro call file;
data x2;
set time;
file "D:\Schedule\Finance 2022\projects\dataMac.txt";
put '%let ymd='ymd';%YmdRun;';

;*%mend;*);*';*";**/;
run;
*to solve the error of NOTE 49-169*;

data x2;
set Sym;
file "D:\Schedule\Finance 2022\projects\StkMac.txt";
put '%let stk='stk';%let mrnk='mrnk'%StkRun;'

;*%mend;*);*';*";**/;
run;
%macro StkRun;

data temp;
	array exAsk(17) _temporary_;
	array exBid(17) _temporary_;
	array xadpth(17) _temporary_;
	array xbdpth(17) _temporary_;
	length tq $1. oex $1. con $4.;
	exchL="ABCDIJKMNTPSTWXYZ"; 
	*Charater set to ID index number of exchange;
	eps=0.0001;
	*recfm: specifies the record format: v=variable format;
	infile "D:\Schedule\Finance 2022\projects\DtaqTxt\&date\&stk..txt" recfm=v missover;
	input tq tm oex pask vbid con bask bbid adpt bdpt;

	*find best Ask, Bid, and total NBBO depth*;
	if tq='Q' then do;
		Expnt=index(exchL,oex);
		if pask<=0 then
		ExAsk(Expnt)=99999;
		else
		ExAsk(Expnt)=pask;
		ExAsk(Expnt)=pask;
		Exbid(Expnt)=vbid;
		Xadpth(Expnt)=adpt;
		Xbdpth(Expnt)=bdpt;
	end;

	minask=min(of ExAsk[*]);
	maxbid=max(of Exbid[*]);

	do i=1 to 17;
		if (ExAsk(i)<=minask+eps) and (ExAsk(i)>=minask-eps) then
		BaskDpth=BaskDpth+Xadpth(i);
		if (Exbid(i)<=maxbid+eps) and (Exbid(i)>=maxbid-eps) then
		BbidDpth=BbidDpth+xbdpth(i);
	end;
	
	if _n_>25 then stop;
run;

%put ---- stock is &stk;
%mend;

options nonotes;
%macro YmdRun;

%include 'D:\Schedule\Finance 2022\projects\StkMac.txt';

%put ------&ymd;

%mend;

%include 'D:\Schedule\Finance 2022\projects\dataMac.txt';
7 REPLIES 7
Tom
Super User Tom
Super User

This step doesn't make any sense.

 

*set stock macro call file;
data x2;
set time;
file "D:\Schedule\Finance 2022\projects\dataMac.txt";
put '%let ymd='ymd';%YmdRun;';

;*%mend;*);*';*";**/;
run;

First get rid of the gibberish at the end.

 

Now look at the PUT statement.  You are writing a string that you are bounding with single quotes.  But you appear to placing single quotes in the string itself.  In that case you need to double the single quotes so SAS knows they are part of the string and marking the boundaries of the string.

 

data x2;
  set time;
  file "D:\Schedule\Finance 2022\projects\dataMac.txt";
  put '%let ymd=''ymd'';%YmdRun;';
run;

So it looks like you are trying to write this code to a file.

 

 

%let ymd='ymd';%YmdRun;

That does seem strange.  Why do you want the single quotes in the value of YMD macro variable?

 

 

Looking at the bigger picture it kind of looks like you are trying to read something in from a text file and pass it to a macro to use.  Notice how your first two data steps are creating actual dataset variables named YMD, STK and MRNK.  And then the other steps seem to be trying to write out SAS code to create macro variables that use the same names as the dataset variables.  So it kind of looks like you want to copy the value read from the text file into the macro variables.

 

In that case perhaps your PUT statement should be more like:

 put '%let ' ymd= ';' 
    / '%YmdRun;'
  ;

This tells SAS to write the string '%let ' (notice the trailing space) then the value of the variable YMD prefixed by its name and an equal sign then a semi-colon and on a new line a call to the macro YMDRUN.

 

In the long run it will probably be better to just write your macros to take their input as PARAMETERS instead of depending on some external macro variable being defined before the macro starts running.

So perhaps something like:

%macro StkRun
(date   /* date string to use in forming the filename */
,stk    /* sticker code to use in forming the filename */
);
%put ---- date is &date;
%put ---- stock is &stk;

data temp;
  array exAsk(17) _temporary_;
  array exBid(17) _temporary_;
  array xadpth(17) _temporary_;
  array xbdpth(17) _temporary_;
  length tq $1. oex $1. con $4.;
  exchL="ABCDIJKMNTPSTWXYZ"; 
  *Charater set to ID index number of exchange;
  eps=0.0001;
  *recfm: specifies the record format: v=variable format;
  infile "D:\Schedule\Finance 2022\projects\DtaqTxt\&date\&stk..txt" recfm=v TRUNCOVER;
  input tq tm oex pask vbid con bask bbid adpt bdpt;

  *find best Ask, Bid, and total NBBO depth*;
  if tq='Q' then do;
    Expnt=index(exchL,oex);
    if pask<=0 then ExAsk(Expnt)=99999;
    else ExAsk(Expnt)=pask;
    ExAsk(Expnt)=pask;
    Exbid(Expnt)=vbid;
    Xadpth(Expnt)=adpt;
    Xbdpth(Expnt)=bdpt;
  end;

  minask=min(of ExAsk[*]);
  maxbid=max(of Exbid[*]);

  do i=1 to 17;
    if (ExAsk(i)<=minask+eps) and (ExAsk(i)>=minask-eps) then BaskDpth=BaskDpth+Xadpth(i);
    if (Exbid(i)<=maxbid+eps) and (Exbid(i)>=maxbid-eps) then BbidDpth=BbidDpth+xbdpth(i);
  end;

  if _n_>25 then stop;
run;
%mend StkRun;

Then your data step might be able to generate the macro call like this instead. It is not clear where the current code is getting the value of the DATE macro variable so let's just tell it to use the value of whatever DATE macro variable already exists as the value for the DATE parameter to the macro.  I am not sure what the other variable read in the step that reads STK is for as it is not used by the STKRUN macro.

put '%stkrun(date=&date,' stk = ');' ;

 

Kurt_Bremser
Super User
data x2;
set time;
file "D:\Schedule\Finance 2022\projects\dataMac.txt";
put '%let ymd='ymd';%YmdRun;';

It does make sense if ymd is a variable in dataset TIME. The file would then contain a series of setting a macro variable and calling the macro.

Cincy
Fluorite | Level 6
;*%mend;*);*';*";**/;
run;

I don't know what's wrong with my code. But if I don't put this coding here, the program for data X2 only gives me error (Note 49-169). 

Kurt_Bremser
Super User

@Cincy wrote:
;*%mend;*);*';*";**/;
run;

I don't know what's wrong with my code. But if I don't put this coding here, the program for data X2 only gives me error (Note 49-169). 


That's not an ERROR, it's a NOTE, and you can remove it by diligently using blanks to make your code more readable:

put '%let ymd=' ymd ';%YmdRun;';
s_lassen
Meteorite | Level 14

So it is the INCLUDE file with Datamac that errs?

 

Try using the SOURCE2 option on the %include statement, so you can see the code submitted, and set the MPRINT option, so you can see the code generated by the macro:

options mprint;
%include 'D:\Schedule\Finance 2022\projects\dataMac.txt' /source2;
Cincy
Fluorite | Level 6
Thank you!
I figure it out!
s_lassen
Meteorite | Level 14
You should probably mark my answer as a solution, then 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 1481 views
  • 4 likes
  • 4 in conversation