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

Hello everyone,

 

Because I had been stuck in this code for an afternoon and cannot pass it on,

and there was not an error nor any output to this code.

I have to post it to ask for help~~~

Thanks for any guidance!

 

options MPRINT;

%MACRO pam(lib=,dsn=,obs=);
%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;
%let lib=WORK;
%let dsn=tb2000;
%let obs=5;
libname &lib "&dirdata";
run;
data &dsn;
infile "&dirdata&lib..&dsn";
proc print data=&dsn &obs; 
title "Listing of first 5 records from &lib, &dsn,";
title2 "on &sysday, &sysdate..";
run;
%mend pam(lib=, dsn=,obs=);


The LOG showed:

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         options MPRINT;
 74         
 75         %MACRO pam(lib=,dsn=,obs=);
 76         %let dirdata=/folders/myfolders;
 77         %let dirOUT=/folders/myfolders;
 78         %let lib=WORK;
 79         %let dsn=tb2000;
 80         %let obs=5;
 81         libname &lib "&dirdata";
 82         run;
 83         data &dsn;
 84         infile "&dirdata&lib..&dsn";
 85         proc print data=&dsn &obs;
 86         title "Listing of first 5 records from &lib, &dsn,";
 87         title2 "on &sysday, &sysdate..";
 88         run;
 89         %mend pam(lib=, dsn=,obs=);
 WARNING: Extraneous text on %MEND statement ignored for macro definition PAM.
 90         
 91         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 104        

What did I miss in the code..:(

Thanks!!!

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

This:

data pam;
infile "&dirdata/Programs/Week_6/tb2000.sas7bdat";
proc print data=pam;
run;

is quite obviously wrong. A .sas7bdat is a SAS dataset, not an external file; it is read with a set statement, or used where needed in a data= option.

So the proper way to go about this is to define a library, and use that to access your dataset.

libname pam "&dirdata./Programs/Week_6/";

proc print data=pam.tb2000;
run;

View solution in original post

22 REPLIES 22
ChrisNZ
Tourmaline | Level 20

 

Extraneous text on %MEND statement ignored for macro definition PAM.

 

Isn't that text clear? 

 

%mend; suffices. No extra parameters.

art297
Opal | Level 21

Since I saw your other post earlier, I think that the following is what you're trying to do:

 

libname testdata '/folders/myfolders';

/*
for test purposes only .. create tb200 using sashelp.class
data testdata.tb2000;
  set sashelp.class;
run;
*/

%MACRO pam(lib=work,dsn=_LAST_,obs=5);
  proc print data=&lib..&dsn. (obs=&obs); 
    title "Listing of first &obs. records from &lib..&dsn.";
    title2 "on &sysday, &sysdate.";
  run;
%mend pam;

%pam(lib=testdata, dsn=tb2000,obs=8)

Art, CEO, AnalystFinder.com

 

jc3992
Pyrite | Level 9

hmm.

even if I get no errors for this code:

options MPRINT;

%MACRO pam;
%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;

libname &lib "&dirdata";
data &dsn;
infile "&dirdata&lib..&dsn";
run;

proc print data=&dsn; 
title "Listing of first 5 records from &lib, &dsn,";
title2 "on &sysday, &sysdate..";
run;
%mend;

The LOG showed:

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         options MPRINT;
 74         
 75         %MACRO pam;
 76         %let dirdata=/folders/myfolders;
 77         %let dirOUT=/folders/myfolders;
 78         
 79         libname &lib "&dirdata";
 80         data &dsn;
 81         infile "&dirdata&lib..&dsn";
 82         run;
 83         
 84         proc print data=&dsn;
 85         title "Listing of first 5 records from &lib, &dsn,";
 86         title2 "on &sysday, &sysdate..";
 87         run;
 88         %mend;
 89         
 90         
 91         
 92         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 105        

But I still have not got any output.

I will run your code to give a try...

 

I think I should get an output with those two titles...:(

jc3992
Pyrite | Level 9

This is the LOG for your code.

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         libname testdata '/folders/myfolders';
 NOTE: Libref TESTDATA refers to the same physical library as WEEK_6.
 NOTE: Libref TESTDATA was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders
 74         
 75         /*
 76         for test purposes only .. create tb200 using sashelp.class
 77         data testdata.tb2000;
 78           set sashelp.class;
 79         run;
 80         */
 81         
 82         %MACRO pam(lib=work,dsn=_LAST_,obs=5);
 83           proc print data=&lib..&dsn. (obs=&obs);
 84             title "Listing of first &obs. records from &lib..&dsn.";
 85             title2 "on &sysday, &sysdate.";
 86           run;
 87         %mend pam;
 88         
 89         %pam(lib=testdata, dsn=tb2000,obs=8)
 MPRINT(PAM):   proc print data=testdata.tb2000 (obs=8);
 ERROR: File TESTDATA.TB2000.DATA does not exist.
 MPRINT(PAM):   title "Listing of first 8 records from testdata.tb2000";
 MPRINT(PAM):   title2 "on Sunday, 11MAR18";
 MPRINT(PAM):   run;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 90         
 91         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 104        
art297
Opal | Level 21

The file '/folders/myfolders/tb2000.sas7bdat' doesn't exist, thus you can't print it.

 

Art, CEO, AnalystFinder.com

 

jc3992
Pyrite | Level 9

I have uploaded it to the library "Week_6" 

And the LOG has not showed that it does not exist.

My code is as below:

options MPRINT;

%MACRO pam;

%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;

libname Week_6 "&dirdata";
data pam;
infile "&dirdata/Programs/Week_6/tb2000.sas7bdat";
proc print data=pam;
run;

%macro pam;
title "Listing of first 5 records from library &lib, member &dsn,";
title2 "on &sysday, &sysdate..";
proc print data=&lib..&dsn(obs=5);
run;
title;
%mend pam;

The LOG:

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 2          TITLE;
 3          FOOTNOTE;
 4          OPTIONS LOCALE=en_US DFLANG=LOCALE;
 5          DATA _NULL_;
 6          RUN;
 7          OPTIONS VALIDVARNAME=V7;
 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 _CLIENTAPPABREV=Studio;
 17         %LET _CLIENTAPPVERSION=3.7;
 18         %LET _CLIENTVERSION=3.7;
 19         %LET _CLIENTMODE=basic;
 20         %LET _SASSERVERNAME=%BQUOTE(localhost);
 21         %LET _SASHOSTNAME=%BQUOTE(localhost);
 22         %LET _SASPROGRAMFILEHOST=%BQUOTE(localhost);
 23         %LET _CLIENTUSERID=%BQUOTE(sasdemo);
 24         %LET _CLIENTUSERNAME=%BQUOTE(sasdemo);
 25         %LET CLIENTMACHINE=%BQUOTE(10.0.2.2);
 26         %LET _CLIENTMACHINE=%BQUOTE(10.0.2.2);
 27         %let SASWORKLOCATION="%sysfunc(getoption(work))/";
 28         FILENAME _CWD '.';
 29         DATA _NULL_;
 30         CALL SYMPUT('_SASWORKINGDIR',PATHNAME('_CWD'));
 31         RUN;
 32         FILENAME _CWD;
 33         
 34         %LET _SASPROGRAMFILE = %NRQUOTE(%NRSTR(/folders/myfolders/Programs/Week_6/ChenJenli_jc3992_Assignment5.sas));
 35         %LET _BASEURL = %BQUOTE(http://localhost:10080/SASStudio/);
 36         %LET _EXECENV=SASStudio;
 37         DATA _NULL_;
 38         CALL SYMPUT("GRAPHINIT","");
 39         CALL SYMPUT("GRAPHTERM","");
 40         RC=TSLVL('GEOCODE','N');
 41         _ERROR_=0;
 42         IF (RC^=' ') THEN DO;
 43         CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;");
 44         CALL SYMPUT("GRAPHTERM","GOPTIONS NOACCESSIBLE;");
 45         END;
 46         RUN;
 47         DATA _NULL_;
 48         RC=SYSPROD("PRODNUM002");
 49         IF (RC^=1) THEN DO;
 50         CALL SYMPUT("GRAPHINIT","");
 51         CALL SYMPUT("GRAPHTERM","");
 52         END;
 53         RUN;
 54         %LET _DATAOUT_MIME_TYPE=;
 55         %LET _DATAOUT_NAME=;
 56         %LET _DATAOUT_TABLE=;
 57         %LET _DATAOUT_URL=;
 58         %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE;
 59         %LET _SASWS_ = %BQUOTE(/folders/myfolders);
 60         %LET _SASWSTEMP_=%BQUOTE(/folders/myfolders/.sasstudio/.images/5758c3cf-6519-489b-8bcc-fb17f767c995);
 61         ODS LISTING CLOSE;
 62         ODS AUTONAVIGATE OFF;
 63         ODS GRAPHICS ON;
 64         ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" ENCODING=utf8  FILE=_HTMLOUT (TITLE='Results:
 64       ! ChenJenli_jc3992_Assignment5.sas') STYLE=Htmlblue OPTIONS(BITMAP_MODE='INLINE' OUTLINE='ON' SVG_MODE='INLINE'
 64       ! CSS_PREFIX='.ods_5758c3cf-6519-489b-8bcc-fb17f767c995' BODY_ID='div_5758c3cf-6519-489b-8bcc-fb17f767c995' );
 65         ODS RTF (ID=WEB) STYLE=Rtf FILE=_RTFOUT sasdate;
 66         ODS PDF (ID=WEB) STYLE=Pearl FILE=_PDFOUT;
 67         &GRAPHINIT;
 68         OPTIONS FIRSTOBS=1;
 69         OPTIONS OBS=MAX;
 70         OPTIONS DTRESET DATE NUMBER NOTES;
 71         OPTIONS NOTES STIMER SOURCE NOSYNTAXCHECK;
 72         
 73         
 74         options MPRINT;
 75         
 76         %MACRO pam;
 77         
 78         %let dirdata=/folders/myfolders;
 79         %let dirOUT=/folders/myfolders;
 80         
 81         libname Week_6 "&dirdata";
 82         data pam;
 83         infile "&dirdata/Programs/Week_6/tb2000.sas7bdat";
 84         proc print data=pam;
 85         run;
 86         
 87         %macro pam;
 88         title "Listing of first 5 records from library &lib, member &dsn,";
 89         title2 "on &sysday, &sysdate..";
 90         proc print data=&lib..&dsn(obs=5);
 91         run;
 92         title;
 93         %mend pam;
 94         
 95         
 96         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 97         ODS HTML CLOSE;
 98         &GRAPHTERM; ;*';*";*/;RUN;QUIT;
 99         QUIT;RUN;
 100        ODS HTML5 (ID=WEB) CLOSE;
 101        
 102        ODS RTF (ID=WEB) CLOSE;
 103        ODS PDF (ID=WEB) CLOSE;
 104        FILENAME _GSFNAME;
 105        DATA _NULL_;
 106        RUN;
 107        OPTIONS VALIDMEMNAME=COMPAT;
 108        OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
 109        
art297
Opal | Level 21

Looks like you created the dataset as a file called pam in your work directory. If so, then all you need is:

%MACRO pam(lib=work,dsn=_LAST_,obs=5);
  proc print data=&lib..&dsn. (obs=&obs); 
    title "Listing of first &obs. records from &lib..&dsn.";
    title2 "on &sysday, &sysdate.";
  run;
%mend pam;

%pam(dsn=pam,obs=8)

Art, CEO, AnalystFinder.com

jc3992
Pyrite | Level 9

Let me try it....

jc3992
Pyrite | Level 9
options MPRINT;



%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;

libname Week_6 "&dirdata" ;
data pam;
infile "&dirdata/Programs/Week_6/tb2000.sas7bdat" ;
proc print data=pam;
run;

%macro pam(lib=WORK, dsn=_LAST_, obs=5);
proc print data=&lib..&dsn.(obs=&obs);
title "Listing of first 5 records from library &lib, member &dsn," ;
title2 "on &sysday, &sysdate.." ;
run;
title;
%mend pam;

%pam(dsn=pam,obs=5);

LOG :

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 bytes long.  You might have unbalanced quotation marks.
 5          DATA _NULL_;
 6          RUN;
 7          OPTIONS VALIDVARNAME=V7;
 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 _CLIENTAPPABREV=Studio;
 17         %LET _CLIENTAPPVERSION=3.7;
 18         %LET _CLIENTVERSION=3.7;
 19         %LET _CLIENTMODE=basic;
 20         %LET _SASSERVERNAME=%BQUOTE(localhost);
 21         %LET _SASHOSTNAME=%BQUOTE(localhost);
 22         %LET _SASPROGRAMFILEHOST=%BQUOTE(localhost);
 23         %LET _CLIENTUSERID=%BQUOTE(sasdemo);
 24         %LET _CLIENTUSERNAME=%BQUOTE(sasdemo);
 25         %LET CLIENTMACHINE=%BQUOTE(10.0.2.2);
 26         %LET _CLIENTMACHINE=%BQUOTE(10.0.2.2);
 27         %let SASWORKLOCATION="%sysfunc(getoption(work))/";
 28         FILENAME _CWD '.';
 29         DATA _NULL_;
 30         CALL SYMPUT('_SASWORKINGDIR',PATHNAME('_CWD'));
 31         RUN;
 32         FILENAME _CWD;
 33         
 34         %LET _SASPROGRAMFILE = %NRQUOTE(%NRSTR(/folders/myfolders/Programs/Week_6/ChenJenli_jc3992_Assignment5.sas));
 35         %LET _BASEURL = %BQUOTE(http://localhost:10080/SASStudio/);
 36         %LET _EXECENV=SASStudio;
 NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
 
            ________________________________________________________________________________________________________________________
            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.
 
 37         DATA _NULL_;
 38         CALL
 38       ! SYMPUT("GRAPHINIT"
                             _
                             49
 38       ! ,"");
 39         CALL
 39       ! SYMPUT("GRAPHTERM"
                             _
                             49
 39       ! ,"");
 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.
 
 40         RC=TSLVL('GEOCODE','N');
 41         _ERROR_=0;
 42         IF (RC^=' ') THEN DO;
 43         CALL SYMPUT("GRAPHINIT","GOPTIONS RESET=ALL GSFNAME=_GSFNAME;");
                                  ___                                    ________________
                                  49                                     49
 44         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.
 
 45         END;
 46         RUN;
 47         DATA _NULL_;
 48         RC=SYSPROD("PRODNUM002"
                                  _
                                  49
 48       ! );
 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.
 
 49         IF (RC^=1) THEN DO;
 50         CALL
 50       ! SYMPUT("GRAPHINIT"
                             _
                             49
 50       ! ,"");
 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.
 
 51         CALL SYMPUT("GRAPHTERM","");
 52         END;
 53         RUN;
 54         %LET _DATAOUT_MIME_TYPE=;
 55         %LET _DATAOUT_NAME=;
 56         %LET _DATAOUT_TABLE=;
 57         %LET _DATAOUT_URL=;
 58         %SYMDEL _DATAOUT_MIME_TYPE _DATAOUT_NAME _DATAOUT_URL _DATAOUT_TABLE;
 59         %LET _SASWS_ = %BQUOTE(/folders/myfolders);
 60         %LET _SASWSTEMP_=%BQUOTE(/folders/myfolders/.sasstudio/.images/a98faac7-1ad7-4d9c-984d-53c7da57687d);
 NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
 61         ODS LISTING CLOSE;
 62         ODS AUTONAVIGATE OFF;
 63         ODS GRAPHICS ON;
 64         ODS HTML5 (ID=WEB) DEVICE=PNG GPATH="&_SASWSTEMP_" ENCODING=utf8  FILE=_HTMLOUT (TITLE='Results:
 64       ! ChenJenli_jc3992_Assignment5.sas') STYLE=Htmlblue OPTIONS(BITMAP_MODE='INLINE' OUTLINE='ON' SVG_MODE='INLINE'
 64       ! CSS_PREFIX='.ods_a98faac7-1ad7-4d9c-984d-53c7da57687d' BODY_ID='div_a98faac7-1ad7-4d9c-984d-53c7da57687d' );
 NOTE: The quoted string currently being processed has become more than 262 bytes long.  You might have unbalanced quotation marks.
 65         ODS RTF (ID=WEB) STYLE=Rtf FILE=_RTFOUT sasdate;
 66         ODS PDF (ID=WEB) STYLE=Pearl FILE=_PDFOUT;
 67         &GRAPHINIT;
 68         OPTIONS FIRSTOBS=1;
 69         OPTIONS OBS=MAX;
 70         OPTIONS DTRESET DATE NUMBER NOTES;
 71         OPTIONS NOTES STIMER SOURCE NOSYNTAXCHECK;
 72         
 73         options MPRINT;
 74         
 75         
 76         
 77         %let dirdata=/folders/myfolders;
 78         %let dirOUT=/folders/myfolders;
 79         
 80         libname Week_6 "&dirdata" ;
 81         data pam;
 82         infile "&dirdata/Programs/Week_6/tb2000.sas7bdat" ;
 83         proc print data=pam;
 82         infile "&dirdata/Programs/Week_6/tb2000.sas7bdat"
                                                            _
                                                            49
 82       !  ;
 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.
 
 84         run;
 85         
 86         %macro pam(lib=WORK, dsn=_LAST_, obs=5);
 87         proc print data=&lib..&dsn.(obs=&obs);
 88         title "Listing of first 5 records from library &lib, member &dsn,"
                                                                             ___________
                                                                             49
 88       !  ;
 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.
 
 89         title2 "on &sysday, &sysdate.." ;
 90         run;
 91         title;
 92         %mend pam;
 93         
 94         %pam(dsn=pam,obs=5);
 95         
 96         
 97         
 98         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 99         ODS HTML CLOSE;
 100        &GRAPHTERM; ;*';*";*/;RUN;QUIT;
 101        QUIT;RUN;
 102        ODS HTML5 (ID=WEB) CLOSE;
 103        
 104        ODS RTF (ID=WEB) CLOSE;
 105        ODS PDF (ID=WEB) CLOSE;
 106        FILENAME _GSFNAME;
 107        DATA _NULL_;
 108        RUN;
 109        OPTIONS VALIDMEMNAME=COMPAT;
 110        OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
 111        

 

art297
Opal | Level 21

Two problems.

 

Fiirst,

81         data pam;
 82         infile "&dirdata/Programs/Week_6/tb2000.sas7bdat" ;
 

is not how you would create the file pam.

 

I would use:

%let dirdata=/folders/myfolders/Programs/Week_6;

data pam;
  set "&dirdata./tb2000";
run;

Then I would use:

%MACRO pam(lib=work,dsn=_LAST_,obs=5);
  proc print data=&lib..&dsn. (obs=&obs); 
    title "Listing of first &obs. records from &lib..&dsn.";
    title2 "on &sysday, &sysdate.";
  run;
%mend pam;

%pam(dsn=pam,obs=8)

Art, CEO, AnalystFinder.com

 

 

 

jc3992
Pyrite | Level 9

Thanks!! But I found I need not create another data name.

I should have used the macro pam as the data name.

So I tried again.

jc3992
Pyrite | Level 9

well...

I thought I have to define it firstly.

 

My understanding of %macro is I had to do it firstly without %macro,

and then project the result I had earlier to the %macro.

So others can make changes with my code on the %macro.

 

Is my understanding correct?

ChrisNZ
Tourmaline | Level 20

%macro pam;

  is the start of the definition of the macro

 

%mend; 

  is the end of the definition

 

%pam; 

  calls the macro

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 22 replies
  • 2830 views
  • 11 likes
  • 4 in conversation