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
SAS Super FREQ

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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