DATA Step, Macro, Functions and more

Creating external file without extension .dat under SAS 9.3

Reply
New User
Posts: 1

Creating external file without extension .dat under SAS 9.3

%Let     Datalib   =         'My-Libname\';
Filename Datalib  "&Datalib."  ;

%Macro   Dummy     ( Name = , N = );

Data     _Null_;

         InFile    DataSeq   Pad       ;

         File      Datalib   (&Name) ;  
     
         Format    Name      $CHAR08.  ;
         Format    ID        $CHAR02.  ;

         Input     ID        01-02
                   Name      20-27     ;

         If        _N_       GT        &N
         And       ID        EQ        './'
         Then      Stop;

         If        _N_       GT        &N
         Then      Put       _INFile_;
Run;

%Mend ;

%DUMMY   ( NAME =  Name
                  , N        = 1);
Run;

NOTE: 4 records were read from the infile DATASEQ.
      The minimum record length was 26.
      The maximum record length was 96.
NOTE: A total of 2 records were written to the file library DATALIB.
      The minimum record length was 256.
      The maximum record length was 256.
NOTE: 2 records were written to the file DATALIB(NAME).
      The minimum record length was 256.
      The maximum record length was 256.

 

Creates file 'Name.dat', but I need NAME only. It works fine by older SAS versions.

SAS Super FREQ
Posts: 806

Re: Creating external file without extension .dat under SAS 9.3

What is your current SAS version?

What was the older SAS version?

 

According to the doc http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n07buc7sg08fdrn1c1..., it is works as documented.

 

I suggest to use 

%let     datalib   =  c:\temp;
%let name = sugus;

data _null_;
  file "&datalib\&name";
  put  "some text";
run;
Super User
Posts: 9,550

Re: Creating external file without extension .dat under SAS 9.3

[ Edited ]

Proper formatting of code really makes life easier. Please compare this functionally equivalent code:

%let datalib = 'My-Libname\';

filename datalib "&datalib.";

%macro dummy(name=, n=);

data _null_;
infile dataseq pad;
file datalib (&name);  
format
  Name $char08.
  ID $char02.
;
input
  ID 01-02
  Name 20-27
;
if _n_ gt &n
then do;
  if ID eq './'
  then stop;
  else put _infile_;
end;
run;

%mend ;

%dummy(name = Name, n = 1);

to your original post. Mind that I converted uppercase to lowercase in all places where uppercase does not have an effect and only makes reading the code harder.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 2 replies
  • 88 views
  • 0 likes
  • 3 in conversation