DATA Step, Macro, Functions and more

Malmqvist macro fails to work on SAS Studio

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

Malmqvist macro fails to work on SAS Studio

[ Edited ]

I am trying to use a macro that was presented at one of the SAS conferences and is avaiable on http://sas-or.com/book/program-9-3

Although I have made the necessary changes to use this macro on SAS Sudio, I am still getting the below error:

The modified code:

 

* Using PROC OPTMODEL for Malmquist Productivity Index and its Components;
option nodate ;
%let _title='Malmquist Productivity Index and its Components';
%let _InData_P1='/home/utoronto/USERNAME/DEA/Data/ind1_in.txt';
%let _OutData_P1='/home/utoronto/USERNAME/DEA/Data/ind1_out.txt';
%let _InData_P2='/home/utoronto/USERNAME/DEA/Data/ind2_in.txt';
%let _OutData_P2='/home/utoronto/USERNAME/DEA/Data/ind2_out.txt';
%let _nInput=1;
%let _nOutput=1;
%let _nUnits=3;
%let _outMalm1=outMalm1;
%let _outMalm2=outMalm2;
%let _Orienta='INPUTMIN'; * Alternative selection is 'OUTPUTMAX';

%macro importdata (txtFile, sasFile);
proc import
	datafile=&txtFile
	out=&sasFile
	dbms=tab
	replace;
	getnames=yes;
run;
%mend importdata;

 

 

The error I am getting: 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 2          TITLE;
 3          FOOTNOTE;
 4          OPTIONS LOCALE=en_US DFLANG=LOCALE;
 NOTE: The quoted string currently being processed has become more than 262 
       characters long.  You might have unbalanced quotation marks.
 5          DATA _NULL_;
 6          RUN;
 7          OPTIONS VALIDVARNAME=ANY;
 8          OPTIONS VALIDMEMNAME=COMPAT;
 9          FILENAME _HTMLOUT TEMP;
 10         FILENAME _RTFOUT TEMP ENCODING='UTF-8';
 11         FILENAME _PDFOUT TEMP;
 12         FILENAME _GSFNAME TEMP;
 13         FILENAME _DATAOUT TEMP;
 14         %LET SYSCC=0;
 15         %LET _CLIENTAPP=SAS Studio;
 16         %LET _CLIENTAPPVERSION=3.6;
 17         %LET _SASSERVERNAME=%BQUOTE(localhost);
 18         %LET _CLIENTUSERID=%BQUOTE(USERNAME);
 19         %LET _CLIENTUSERNAME=%BQUOTE();
 20         %LET CLIENTMACHINE=%BQUOTE(WRDS-HAPROXY1-W.WHARTON.PRIVATE);
 21         
 87         &GRAPHTERM; ;*';*";*/;RUN;QUIT;
                             ______________
                             49
 NOTE 49-169: The meaning of an identifier after a quoted string might change in 
              a future SAS release.  Inserting white space between a quoted 
              string and the succeeding identifier is recommended.
 
 22         %LET _SASPROGRAMFILE =
 22       ! %BQUOTE(/home/utoronto/USERNAME/Malmqvist_working_on.sas);
 23         %LET _BASEURL =
 23       ! %BQUOTE(https://wrds-cloud.wharton.upenn.edu/SASStudio/);
 24         %LET _EXECENV=SASStudio;
 25         DATA _NULL_;
 26         CALL
 26       ! SYMPUT("GRAPHINIT"
                             _
                             49
 26       ! ,"");
 27         CALL SYMPUT("GRAPHTERM","");
                                  ______
                                  49
 NOTE 49-169: The meaning of an identifier after a quoted string might change in 
              a future SAS release.  Inserting white space between a quoted 
              string and the succeeding identifier is recommended.
 
 28         RC=TSLVL('GEOCODE','N');
 29         _ERROR_=0;
 30         IF (RC^=' ') THEN DO;
 31         CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;");
                                  ___
 ________________                                                                
                                  49                                     49
 32         CALL SYMPUT("GRAPHTERM","GOPTIONS NOACCESSIBLE;");
                                  ___
 ___________________________________                                             
                                  49                       49
 NOTE 49-169: The meaning of an identifier after a quoted string might change in 
              a future SAS release.  Inserting white space between a quoted 
              string and the succeeding identifier is recommended.
 
 33         END;
 34         RUN;
 35         DATA _NULL_;
 36         RC=SYSPROD("PRODNUM002"
                                  _
                                  49
 36       ! );
 NOTE 49-169: The meaning of an identifier after a quoted string might change in 
              a future SAS release.  Inserting white space between a quoted 
              string and the succeeding identifier is recommended.
 
 37         IF (RC^=1) THEN DO;
 38         CALL
 38       ! SYMPUT("GRAPHINIT"
                             _
                             49
 38       ! ,"");
 NOTE 49-169: The meaning of an identifier after a quoted string might change in 
              a future SAS release.  Inserting white space between a quoted 
              string and the succeeding identifier is recommended.
 
 39         CALL SYMPUT("GRAPHTERM","");
 40         END;
 41         RUN;
 42         %LET _DATAOUT_MIME_TYPE=;
 43         %LET _DATAOUT_NAME=;
 44         %LET _DATAOUT_TABLE=;
 45         %LET _DATAOUT_URL=;
 46         %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE;
 47         %LET _SASWS_ = %BQUOTE(/home/utoronto/USERNAME);
 48         %LET
 48       ! _SASWSTEMP_=%BQUOTE(/home/utoronto/USERNAME/.images/9bf5a667-be1f-43d
 48       ! 6-8756-d97b7ffa754c);
 NOTE: The quoted string currently being processed has become more than 262 
       characters long.  You might have unbalanced quotation marks.
 49         ODS LISTING CLOSE;
 50         OPTIONS PRINTERPATH=PDF;
 51         ODS AUTONAVIGATE OFF;
 52         ODS GRAPHICS ON;
 53         ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" ENCODING=utf8
 53       ! FILE=_HTMLOUT (TITLE='Results: Malmqvist_working_on.sas')
 53       ! STYLE=Htmlblue OPTIONS(BITMAP_MODE='INLINE' OUTLINE='ON'
 53       ! SVG_MODE='INLINE'
 53       ! CSS_PREFIX='.ods_9bf5a667-be1f-43d6-8756-d97b7ffa754c'
 53       ! BODY_ID='div_9bf5a667-be1f-43d6-8756-d97b7ffa754c' );
 54         ODS RTF (ID=WEB) STYLE=Rtf FILE=_RTFOUT sasdate;
 NOTE: The quoted string currently being processed has become more than 262 
       characters long.  You might have unbalanced quotation marks.
 55         ODS PDF (ID=WEB) STYLE=Pearl FILE=_PDFOUT;
 56         &GRAPHINIT;
 57         OPTIONS FIRSTOBS=1;
 58         OPTIONS OBS=MAX;
 59         OPTIONS DTRESET DATE NUMBER NOTES;
 60         OPTIONS NOTES STIMER SOURCE NOSYNTAXCHECK;
 61         
 62         option nodate ;
 63         %let _title='Malmquist Productivity Index and its Components';
 64         %let _InData_P1='/home/utoronto/USERNAME/DEA/Data/ind1_in.txt';
 65         %let _OutData_P1='/home/utoronto/USERNAME/DEA/Data/ind1_out.txt';
 66         %let _InData_P2='/home/utoronto/USERNAME/DEA/Data/ind2_in.txt';
 67         %let _OutData_P2='/home/utoronto/USERNAME/DEA/Data/ind2_out.txt';
 68         %let _nInput=1;
 69         %let _nOutput=1;
 70         %let _nUnits=3;
 71         %let _outMalm1=outMalm1;
 72         %let _outMalm2=outMalm2;
 73         %let _Orienta='INPUTMIN'; * Alternative selection is 'OUTPUTMAX';
 74         
 75         %macro importdata (txtFile, sasFile);
 76         proc import
 77         datafile=&txtFile
 78         out=&sasFile
 79         dbms=tab
 80         replace;
 81         getnames=yes;
 82         run;
 83         %mend importdata;
 84         
 85         
 86         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 87         ODS HTML CLOSE;
 88         &GRAPHTERM; ;*';*";*/;RUN;QUIT;
 89         QUIT;RUN;
 90         ODS HTML5 (ID=WEB) CLOSE;
 91         
 92         ODS RTF (ID=WEB) CLOSE;
 93         ODS PDF (ID=WEB) CLOSE;
 94         FILENAME _GSFNAME;
 95         DATA _NULL_;
 96         RUN;
 97         OPTIONS VALIDMEMNAME=COMPAT;
 98         OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
 99         

 

I am not sure where the error is happening. So I am stuck and would appreciate any help. Attached are the samples I am using in the code. 


Accepted Solutions
Solution
‎07-06-2017 01:37 AM
Super User
Posts: 19,772

Re: Malmqvist macro fails to work on SAS Studio

Writing out the imports won't have an effect on further steps as long as they have the same names. 

 

However, I can't see what's wrong with your code because you're using macro variables in the call. Are there file paths in quotes? 

View solution in original post


All Replies
Frequent Contributor
Posts: 110

Re: Malmqvist macro fails to work on SAS Studio

The errors are occuring because of the following part of the code:

%macro importdata (txtFile, sasFile);
proc import
	datafile=&txtFile
	out=&sasFile
	dbms=tab
	replace;
	getnames=yes;
run;
%mend importdata;


Should I just write the proc import for each dataset? But then the issue becomes that I am deviatng from the macro (e.g., I will not be able to use the part below) that is suggested to be used to calculate the malmqvist index. 

* The data handling macro;
%macro data;
* Import text tab delimited input variables to SAS data file, period1;
%importdata(&_InData_P1,data9_3_input_P1);
* Import text tab delimited output variables to SAS data file, period1;
%importdata(&_OutData_P1,data9_3_output_P1);
* Import text tab delimited input variables to SAS data file, period2;
%importdata(&_InData_P2,data9_3_input_P2);
* Import text tab delimited output variables to SAS data file, period2;
%importdata(&_OutData_P2,data9_3_output_P2);
%mend data;
* A DEA macro for CRS output orientation;
%macro model_outOri ( per1, per2,j0);




Solution
‎07-06-2017 01:37 AM
Super User
Posts: 19,772

Re: Malmqvist macro fails to work on SAS Studio

Writing out the imports won't have an effect on further steps as long as they have the same names. 

 

However, I can't see what's wrong with your code because you're using macro variables in the call. Are there file paths in quotes? 

Super User
Posts: 7,764

Re: Malmqvist macro fails to work on SAS Studio

The first messages indicate that you have an unbalanced double quote from the code that ran before. So it points to a problem with quotes/quoting in the way you use the macro variables.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 19,772

Re: Malmqvist macro fails to work on SAS Studio

Posted in reply to KurtBremser

KurtBremser wrote:

The first messages indicate that you have an unbalanced double quote from the code that ran before. So it points to a problem with quotes/quoting in the way you use the macro variables.


The log starts from 1, so it's a clean session. I think that's the way SAS Studio operates, more of a batch submission style. 

 

It it looks like an error that was previously in SAS Studio but fixed a while ago. But you can easily check if any code runs to see if it's an error on WRDS or your code. 

Super User
Posts: 7,764

Re: Malmqvist macro fails to work on SAS Studio

Actually, I now think that log is somehow fake.

Why?

First line:

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;

After that, we should not see any log lines until after options source appears in the code.

My SAS Studio shows line 1 and then something like line 68, completely hiding the Studio-start code.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Super User
Posts: 7,942

Re: Malmqvist macro fails to work on SAS Studio

Totally off topic from your question, I am not suprised there is so many bad coding practices being learnt if SAS provided scripts are this bad per what you have posted.  Just from a brief glance:

All uppercase coding

Macro variables without '.' to complete them

Use of 

;*';*";*/;RUN;QUIT; 

or as I like to think of it - "My program will likely fail, try to cover it up"

There is a data _null_; run; which doesn't appear to do anything.

Also seems to be that all coding should be done using macro programming 

Frequent Contributor
Posts: 110

Re: Malmqvist macro fails to work on SAS Studio

[ Edited ]

I was finally able to find out why the error was thank to your replies - you have pointed me to the right direction:

 

  1. The macro requires that the number of row (i.e., distinct units) is identical for each dataset (_InData_P1, _InData_P2, _OutData_P1, _OutData_P2). 
  2. Another issue that led to the errors in the macro was that the datasets had to be constructed in a certain way (DMU, input1, input2, etc.).
  3. Lastly, there was a bug in the macro itself that was causing additional headaches (thank to the log file, these few errors were easily identifiable but the first two were trickier).

 

A big thank you to you all, @Reeza@KurtBremser@RW9. You all are great SAS mentors! 


 

Frequent Contributor
Posts: 110

Re: Malmqvist macro fails to work on SAS Studio

[ Edited ]

To select the answer, I would prefer to collectively choose you all. :-) Unfortunately, there is no such an option on here. So I will go ahead and accept the first reply (actually, I have used a random number generator to select which one to choose as the answer). Although all of your replies were helpful. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 177 views
  • 7 likes
  • 4 in conversation