BookmarkSubscribeRSS Feed
hellohere
Pyrite | Level 9
The code is straightforward, to get the dif from two variables. The dataset has the two variables, which are both
of numeric.

But the one inside marco complains. The "same" code works ok without macro.

Anyone?!

MPRINT(DOLOOP): proc sql ; MPRINT(DOLOOP): select avg(IF)-avg(dlastprice) into: lpadj from hs300_0604 ; ERROR: The AVG summary function requires a numeric argument. MPRINT(DOLOOP): quit; NOTE: The SAS System stopped processing this step because of errors. NOTE: PROCEDURE SQL used (Total process time): real time 0.00 seconds cpu time 0.00 seconds 59956 proc sql; 59957 select avg(IF)-avg(dlastprice) from hs300_0604 ; 59958 quit; NOTE: PROCEDURE SQL used (Total process time): real time 0.03 seconds cpu time 0.01 seconds
5 REPLIES 5
hellohere
Pyrite | Level 9

Anyway/Macro to tell which one variable at a dataset is numeric or not?!

 

So can use ahead of the SQL to avoid complains?!

Patrick
Opal | Level 21

Works for me. Verify that both of your variables are of type numeric.

data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

proc sql noprint;
  select avg(IF)-avg(dlastprice) into :lpadj 
  from hs300_0604
  ;
quit;
%put &=lpadj;
38         %put &=lpadj;
LPADJ=       1

 

Update: As a reaction on what @yabwon posted (worth testing) the code also works for me within a macro.

data hs300_0604;
  if=2; dlastprice=1;output;
  if=4; dlastprice=3;output;
run;

%macro doit(param1,param2);
  proc sql noprint;
    select avg(&param1)-avg(&param2) into :lpadj 
    from hs300_0604
    ;
  quit;
  %put &=lpadj;
%mend;

options mprint;
%doit(if,dlastprice);
MPRINT(DOIT):   proc sql noprint;
MPRINT(DOIT):   select avg(if)-avg(dlastprice) into :lpadj from hs300_0604 ;
MPRINT(DOIT):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

LPADJ=       1

 

yabwon
Onyx | Level 15

inside your macro code make it:

 

select %unquote(avg(&whatEverMacrovariabeYouHaveHere.)-%unquote(avg(&whatOtherMacrovariabeYouHaveThere.))
into ...

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



yabwon
Onyx | Level 15

And if I was right, read this article by Susan O'Connor: https://stats.oarc.ucla.edu/wp-content/uploads/2016/02/bt185.pdf

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

Hard to tell since you did not provide the macro.

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!

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
  • 5 replies
  • 345 views
  • 0 likes
  • 4 in conversation