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

Thanks!! After getting a coffee and re-think it over again.

Here is my code, but Ive got errors which I do not know where to start working with...:(

Need help! 

 

%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;
%let lib=WORK;
%let dsn=_LAST_;
%let obs=5;

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

%pam;

The LOG is as below:

 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         
 74         %let dirdata=/folders/myfolders;
 75         %let dirOUT=/folders/myfolders;
 76         %let lib=WORK;
 77         %let dsn=_LAST_;
 78         %let obs=5;
 79         
 80         %macro pam(lib=,dsn=,obs=);
 81         proc print data=&dirdata&lib..&dsn.(obs=5);
 82         title "Listing of first 5 records from library &lib, member &dsn," ;
 83         title2 "on &sysday, &sysdate.." ;
 84         run;
 85         %mend pam;
 86         
 87         %pam;
 MPRINT(PAM):   proc print data=/folders/myfolders.(obs=5);
 MPRINT(PAM):   title "Listing of first 5 records from library , member ," ;
 NOTE: Line generated by the macro variable "LIB".
 87         /folders/myfolders
            _
            22
            76
 ERROR 22-322: Expecting a name.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 MPRINT(PAM):   title2 "on Monday, 12MAR18." ;
 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.01 seconds
       
 88         
 89         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 102        

I did not get why the LOG showed that on Line 88 I need a name for that?

That was macro calling. But I felt if SAS had not found the file or did I do wrong with the path so it did not print out anything?

ChrisNZ
Tourmaline | Level 20

parameter lib=   should be a library

 

libname DATA '/folders/myfolders';

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

%pam(lib=WORK, dsn=_LAST_, obs=5);
or
%pam(lib=DATA, dsn=_LAST_, obs=5);

 

jc3992
Pyrite | Level 9

After reading @Tom comment,

I changed to this :

options MPRINT;


%let dirdata=/folders/myfolders;
%let dirOUT=/folders/myfolders;
%let lib=Week_6;
libname Week_6 "&dirdata";
data tb2000;
infile "&dirdata/Programs/Week_6/tb2000.sas7bdat";
proc print data=tb2000;
run;

%macro pam(lib=,dsn=,obs=);

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

My mindset was,

I should run the statement and then define the macro function and then call the macro function.(But I wanted to try to print out firstly and then put macro in it and then call the macro, so I had not run to that step yet because there were errors...)

 

 

 

The LOG is as below:

 
 
1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         
 74         options MPRINT;
 75         
 76         
 77         
 78         %let dirdata=/folders/myfolders;
 79         %let dirOUT=/folders/myfolders;
 80         %let lib=Week_6;
 81         libname Week_6 "&dirdata";
 NOTE: Libref WEEK_6 refers to the same physical library as PERM.
 NOTE: Libref WEEK_6 was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders
 82         data tb2000;
 83         infile "&dirdata/Programs/Week_6/tb2000.sas7bdat";
 
 NOTE: The infile "/folders/myfolders/Programs/Week_6/tb2000.sas7bdat" is:
       Filename=/folders/myfolders/Programs/Week_6/tb2000.sas7bdat,
       Owner Name=sasdemo,Group Name=sas,
       Access Permission=-rw-rw-r--,
       Last Modified=10Mar2018:22:36:26,
       File Size (bytes)=50176
 
 NOTE: 0 records were read from the infile "/folders/myfolders/Programs/Week_6/tb2000.sas7bdat".
 NOTE: The data set WORK.TB2000 has 1 observations and 0 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 84         proc print data=tb2000;
 
 85         run;
 
 NOTE: No variables in data set WORK.TB2000.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 86         
 87         
 88         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 101        
 

And there was a message saying that "Work.tb2000" has no column in it popping out.

My hand is tired I need to rest a bit....

Used a 13" Mac book for this...:(

 

 

 

ChrisNZ
Tourmaline | Level 20

You can read a sas table (sas7bdat file) with infile.

 

Run my code.

jc3992
Pyrite | Level 9

This is the LOG of your code:

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73          libname DATA '/folders/myfolders';
 NOTE: Libref DATA refers to the same physical library as WEEK_6.
 NOTE: Libref DATA was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders
 74         
 75         %macro pam(lib=,dsn=,obs=);
 76           proc print data=&lib..&dsn.(obs=&obs);
 77           title "Listing of first &obs records from library &lib, member &dsn," ;
 78           title2 "on &sysday, &sysdate.." ;
 79           run;
 80         %mend pam;
 81         
 82         
 83         
 84         %pam(lib=DATA, dsn=_LAST_, obs=8);
 MPRINT(PAM):   proc print data=DATA._LAST_(obs=8);
 MPRINT(PAM):   title "Listing of first 8 records from library DATA, member _LAST_," ;
 MPRINT(PAM):   title2 "on Monday, 12MAR18." ;
 MPRINT(PAM):   run;
 NOTE: No variables in data set WORK.TB2000.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 85         
 86         
 87         
 88         
 89         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 102        

Why is there no variable in dataset WORK.2000?

I tried to change the "libname" to "WORK"

but the LOG showed "the WORK cannot be reassigned".

 

Was this what the question want?

 

ChrisNZ
Tourmaline | Level 20
> Why is there no variable in dataset WORK.2000?
You should know. Not us.

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;
jc3992
Pyrite | Level 9

Thank you!

It worked. My code is:

options MPRINT;


libname DATA '/folders/myfolders';
data tb2000;
set "/folders/myfolders/Programs/Week_6/tb2000.sas7bdat";
proc print data=tb2000;
run;

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



%pam(lib=WORK, dsn=_LAST_, obs=8);

LOG:

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 72         
 73         
 74         options MPRINT;
 75         
 76         
 77         libname DATA '/folders/myfolders';
 NOTE: Libref DATA was successfully assigned as follows: 
       Engine:        V9 
       Physical Name: /folders/myfolders
 78         data tb2000;
 79         set "/folders/myfolders/Programs/Week_6/tb2000.sas7bdat";
 NOTE: Data file _TEMP2.TB2000.DATA is in a format that is native to another host, or the file encoding does not match the session 
       encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce 
       performance.
 
 NOTE: There were 201 observations read from the data set /folders/myfolders/Programs/Week_6/tb2000.sas7bdat.
 NOTE: The data set WORK.TB2000 has 201 observations and 22 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds
       
 80         proc print data=tb2000;
 
 81         run;
 
 NOTE: There were 201 observations read from the data set WORK.TB2000.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           1.54 seconds
       cpu time            1.53 seconds
       
 
 82         
 83         %macro pam(lib=,dsn=,obs=);
 84           proc print data=&lib..&dsn.(obs=&obs);
 85           title "Listing of first &obs records from library &lib, member &dsn," ;
 86           title2 "on &sysday, &sysdate.." ;
 87           run;
 88         %mend pam;
 89         
 90         
 91         
 92         %pam(lib=WORK, dsn=_LAST_, obs=8);
 MPRINT(PAM):   proc print data=WORK._LAST_(obs=8);
 MPRINT(PAM):   title "Listing of first 8 records from library WORK, member _LAST_," ;
 MPRINT(PAM):   title2 "on Monday, 12MAR18." ;
 MPRINT(PAM):   run;
 NOTE: There were 8 observations read from the data set WORK.TB2000.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.11 seconds
       cpu time            0.11 seconds
       
 
 93         
 94         
 95         
 96         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 109        

Still got one day to go through other questions...Whole weekend for SAS...But thanks for everyone. Thanks!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2956 views
  • 11 likes
  • 4 in conversation