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?
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);
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...:(
You can read a sas table (sas7bdat file) with infile.
Run my code.
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?
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;
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!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.