I'm having basically the same issue as the following post:Proc Data sets argument error- Error 22-322 expecting a name
But the answer didn't solve my problem.
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
libname indata "E:\el30053_54_55\el30053-postprocessor\output\files";
/* Format HYPO1001 variables */
PROC datasets library=INDATA;
MODIFY INDATA.hypo1001
/* Format section. */
format HYPOR1;
/* Should not need to edit anything below. */
run;
quit;`
Essentially, I have several datasets in the library INDATA. One of them is called hypo1001. Bottom line, I need to rename some of the variables in the dataset, but the rename statement isn't working because there are a few variables with invalid formats. So now I'm trying to fix the formats, but it doesn't seem to be working. From what I can tell, my syntax is correct, but I have very limited experience with SAS that doesn't usually extend much beyond just converting xpt files to SAS format.
I'm getting the following errors in the log:
ERROR 22-322: Expecting a name.
ERROR 201-322: The option is not recognized and will be ignored.
The libref you used to define the library should not be included in the member name that you use in the MODIFY statement. Try this example:
data class; set sashelp.class; run;
proc datasets nolist lib=work;
modify class ;
format name ;
run;
quit;
Related
I am trying to use the %Dropmiss Macro in sas, which I found from an official PDF https://support.sas.com/resources/papers/proceedings10/048-2010.pdf
however, when I try to use it, I always get the same error:
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
"%qtrim(&&CHARMAX&I)" eq ""
Being a newbie in Macros, I have tried to find a solution everywhere , but nothing so far. What is possibly the problem? What should I do or check in my data to fix the problem.
Thank you,
Not sure about your macro but you don't need a macro. That paper is a decade old so here's a more modern approach.
ods select none;
ods output nlevels=temp;
proc freq data=have nlevels;
tables _all_;
run;
proc sql;
select tablevar into : drop separated by ','
from temp
where NNonMissLevels=0;
alter table data&i
drop &drop;
quit;
Original source, since not my code:
https://communities.sas.com/t5/SAS-Programming/deleting-empty-columns/m-p/308045
On our ZOS (mainframe) we have a library called
USER.PGM.WEEKLY
where several sas programs(members) are located
I am trying to retrieve a list of all the member from my PCSAS with following code
rsubmit;
proc source indd='C009BSA.BSA.BIBHLP.SAS' select *; print;run;
endrsubmit;
signoff;
But it errors out with
ERROR 22-322: Syntax error, expecting one of the following: ;, DIRDD, INDD, MAXIOERROR, NOALIAS,
NODATA, NOMEM, NOPRINT, NOSUMMARY, NOTSORTED, NULL, OUTBLK, OUTDD, PAGE, PRINT,
SEARCH.
ERROR 180-322: Statement is not valid or it is used out of proper order.
I have tried to google around to find the solution but haven't been able to sort it out.
How ever i am able to download one member at the time by running
filename inpds 'USER.PGM.WEEKLY' shr;
proc download infile =inpds(PPRINT_TO_PDF)
outfile='L:\Work\PPRINT_TO_PDF';
run;
Try something like this. You might need to use an actual physical file instead of using the TEMP filename engine on ZOS.
filename dirlist temp;
rsubmit;
filename dirlist temp;
proc source indd='C009BSA.BSA.BIBHLP.SAS' dirdd=dirlist; run;
proc download infile=dirlist outfile=dirlist; run;
endrsubmit;
https://v8doc.sas.com/sashtml/os390/z0217440.htm
If you just want to download all of the members of the PDS then PROC DOWNLOAD can do that for you without you needing to have the list of members.
filename outdir '/where/I/want/to/write/';
rsubmit;
filename indir 'C009BSA.BSA.BIBHLP.SAS';
proc download infile=indir(*) outfile=outdir; run;
endrsubmit;
I want to change dataset names in SAS using concatenated macro variables. Using the example code below I get an error. Is my syntax wrong or is it not possible to use a concatenating function in this way?
Code:
%let term=201610;
%let emp='bob';
Proc Datasets library=work;
change testset = cat(&emp,&term);
run;
Errors Received:
ERROR 22-322: Syntax error, expecting one of the following: ALTER, MEMTYPE, MT, MTYPE, PROTECT, PW, READ, WRITE.
ERROR 76-322: Syntax error, statement will be ignored.
You don't need to concatenate macro variables, it's like a find and replace text.
Because you have quotes right now this is what would happen:
change testset = cat('bob', 201610)
But the CAT function is not valid there. You could technically use %SYSFUNC() to use the CAT function but there's an easier way.
%let term=201610;
%let emp='bob';
Proc Datasets library=work;
change testset = &emp&term.;
run;quit;
Note that PROC DATASETS requires a QUIT to terminate.
I have a SAS EG program that checks if a file exists and refuses to replace it if it dose exists.
When this happens I want SAS EG to show an error on that program and display a meaningful custom error message in the log. And I want the error message to look the same as other error messages people are used to seeing in the log so they pay attention to it.
For now I have just imported a file with a name of my error message. This is not great because it appends file not found messages to the message I want to display.
Is there any way I can declare that there is an error and provide an error message to put in the LOG
The SAS log uses a very simple way to change text color: the first word in the line of text to display in the log. You can recreate ERROR, WARNING, and NOTE messages in both %put and put statements.
%put NOTE: This is a note;
%put WARNING: This is a warning;
%put ERROR: I AM ERROR;
For example, let's say you want to display an error if a certain value is missing.
data have;
input var;
datalines;
1
.
2
3
.
;
run;
%put NOTE: Now checking for missing values...;
data _null_;
set have;
if(missing(var) ) then
put 'ERROR: A missing value for "var" was found at observation ' _N_;
run;
You can also do this with macros, such as creating a flag during certain check steps, or using the &syserr automatic macro variable.
%macro check;
%let e = 0;
data _null_;
set have;
if(missing(var) ) then call symput('e', 1);
run;
%if(&e) %then %put ERROR: An error was found.;
%mend;
I have numerous SAS datasets on my Windows 7 / SAS 9.4 machine:
data_19921.sas7bdat
data_19922.sas7bdat
data_19923.sas7bdat
....
data_200212.sas7bdat
etc. The format is data_YYYYM.sas7bdat or data_YYYYMM.sas7bdat (the latter for two digit months) and every dataset has identical variables and formatting. I'm trying to iterate over all of these files and append them into one big SAS dataset. The datasets were created on some Unix machine elsewhere in my company that I don't have access to. When I try to append the files:
%let root = C:\data;
libname in "&raw\in";
libname out "&raw\out";
/*****************************************************************************/
* initialize final data set but don't add any observations to it;
data out.alldata;
set in.data_19921;
stop;
run;
%macro append_files;
%do year=1992 %to 2002;
%do month=1 %to 12;
proc append data=out.alldata base=in.data_&year&month;
run;
%end;
%end;
%mend;
%append_files;
I get errors that say
File in.data_19921 cannot be updated because its encoding does not match the session encoding or the file is in a format native to another host, such as LINUX_32, INTEL_ABI
I don't have access to the Unix machine that created these datasets (or any Unix machine right now), so I don't think I can use proc cport and proc cimport.
How can I read/append these data sets on my Windows machine?
You can use the colon operator or dash to shortcut your process:
data out.alldata;
set in.data_:;
run;
OR
data out.alldata;
set in.data19921-in.data200212;
run;
If you have variables that are different lengths you may get truncation. SAS will warn you though:
WARNING: Multiple lengths were specified for the variable name by input data set(s). This may
cause truncation of data.
One way to avoid it is to create a false table first, using the original table. The following SQL code will generate the CREATE Table statements and you can modify the lengths manually as needed.
proc sql;
describe table in.data19921;
quit;
*run create table statement here with modified lengths;
data out.alldata;
set fake_data (obs=0)
in.data19921-in.data200212;
run;