BookmarkSubscribeRSS Feed
Abishekaa
Obsidian | Level 7

Hi all, I get the following syntax error when naming multiple datasets using hyphen in sas and it's very confusing. Could someone please shed some light on why this error comes up? Thanks in advance!

5756  data test1-test10;
                -
                22
                200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, /, ;,
              _DATA_, _LAST_, _NULL_.

ERROR 200-322: The symbol is not recognized and will be ignored.

5757      set audiores;
5758      if a=1 and b=1 then output test1;
5759      if a=1 and b=0 then output test2;
                                     -----
                                     455
ERROR 455-185: Data set was not specified on the DATA statement.

5760  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST1 may be incomplete.  When this step was stopped there were 0
         observations and 95 variables.
WARNING: The data set WORK.TEST10 may be incomplete.  When this step was stopped there were 0
         observations and 95 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds

5 REPLIES 5
Tom
Super User Tom
Super User

Because you cannot have a dataset LIST there.  Spell out the names.

data test1 test2 test3 ....
Abishekaa
Obsidian | Level 7

Thank you, Tom! I did not know that.

 

Would there be an easier way to list consecutive dataset names? I have to create about 50 output datasets in the program, so the dataset name list would like test1...test50

 

 

andreas_lds
Jade | Level 19

You could use a macro-loop to create the names. But having to create 50 datasets seems to be a bit strange. Why do you need them?

ballardw
Super User

@Abishekaa wrote:

Thank you, Tom! I did not know that.

 

Would there be an easier way to list consecutive dataset names? I have to create about 50 output datasets in the program, so the dataset name list would like test1...test50

 

 


You code makes me think you might be better served to create a grouping variable with that block of if/then code and then use BY Group processing later.

Or please describe exactly how you are going to use those 50 data sets later.

Tom
Super User Tom
Super User

Assuming there is a valid reason you need to actually do this then that type of "wallpaper" code is best generated through code generation.  In your case it looks like you need a dataset with three variables to drive the code generation.  Something like:

data rules;
  input dsname :$32. a b ;
cards;
test1 1 1
test2 1 0
;

You could then use that dataset to create the code:

filename code temp;
data _null_;
  set rules end=eof;
  file code lrecl=72;
  if _n_=1 then put 'data ' @;
  put dsname @;
  if eof then put / ';' ;
run;
data _null_;
  set rules end=eof;
  file code lrecl=72 mod;
  put @3 'if ' a= 'and ' b= 'then output ' dsname ';' ;
  if eof then put 'run;' ;
run;

You can then run the generated code using the %INCLUDE statement.

%include code / source2;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 1073 views
  • 0 likes
  • 4 in conversation