BookmarkSubscribeRSS Feed
KM11
Calcite | Level 5

%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.

2 REPLIES 2
BrunoMueller
Meteorite | Level 14

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;
Kurt_Bremser
Super User

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.

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1722 views
  • 0 likes
  • 3 in conversation