DATA Step, Macro, Functions and more

infile date in a single record

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

infile date in a single record

Hi to all!!!

I have to read one file with only one SINGLE record and put it in SAS table with more records. the file is with this one record:

19941231 C   19950216 19950216 16000000 18300000                                19951231 C T 19960226 19960226 17060000 20150000                                19961130     19961207 19961207 10000000 18000000 ......               ..................                              .....................................               ......................

obviously the record is more  long.

In general I make infile with multiple record and I hadn't any problems but I have some problems to create a sas program which reads only this record.

have you some idea?


Accepted Solutions
Solution
‎05-30-2013 09:08 AM
Respected Advisor
Posts: 3,799

Re: infile date in a single record

I reckon LRECL=N is what you need.  Notice I remove @@;

data grate;
   infile '~/prova' recfm=N;
   input elab 8. +1 ch $1. +1 sw $1. +1 init 8. +1 fin 8. +1 hourIni 8. +1 hourFin 8. +32;
  
run

View solution in original post


All Replies
Regular Contributor
Posts: 195

Re: infile date in a single record

Can you please define your multiple records in a meaningful way to prepare the SAS Codes from it...

In your post, what all those number represants ??? if you simply want to read one line which contains many variables then use double trailing @@ in your INPUT statement like this...

Input variable_name @@;

-Urvish

Contributor
Posts: 22

Re: infile date in a single record

Posted in reply to UrvishShah

hi,

I can't define the files which I have to read.....

the layout is this:

data-elaboration          8      (aaaammgg)

filler1                         $1

ch                             $1

filler2                         $1

sw                            $1

filler3                        $1

data-initialization         8  (aaaammgg)

filler4                         $1

data-fin                     8 (aaaammgg)

filler5                        $1

hour-ini                    8

filler5                         $1

hour-fin                    8

filler7                        $32

the filler are always missing(' '), and ch or sw can be missing(' ') or one single charachter.

and the files contains only one record:

19941231 C   19950216 19950216 16000000 18300000                                19951231 C T 19960226 19960226 17060000 20150000                                19961130     19961207 19961207 10000000 18000000                                19961231     19970105 19970105 10000000 18000000...............................................................                    ....................................

if you have some idea I'm gratefull...

thanks...

Respected Advisor
Posts: 3,799

Re: infile date in a single record

This looks about right.

filename FT15F001 temp lrecl=1024;
parmcards;
19941231 C   19950216 19950216 16000000 18300000                                19951231 C T 19960226 19960226 17060000 20150000                                19961130     19961207 19961207 10000000 18000000                                19961231     19970105 19970105 10000000 18000000
;;;;
   run;
  
data grate;
   infile FT15F001;
   input elab 8. +1 ch $1. +1 sw $1. +1 init 8. +1 fin 8. +1 hourIni 8. +1 hourFin 8. +32 @@;
   run;  
Contributor
Posts: 22

Re: infile date in a single record

Posted in reply to data_null__

Hi,

can you try with the file which I have attached in this response...

because, my programm don't finish..

Attachment
Solution
‎05-30-2013 09:08 AM
Respected Advisor
Posts: 3,799

Re: infile date in a single record

I reckon LRECL=N is what you need.  Notice I remove @@;

data grate;
   infile '~/prova' recfm=N;
   input elab 8. +1 ch $1. +1 sw $1. +1 init 8. +1 fin 8. +1 hourIni 8. +1 hourFin 8. +32;
  
run
Contributor
Posts: 22

Re: infile date in a single record

Posted in reply to data_null__

THANKS!!!!!!!

Regular Contributor
Posts: 195

Re: infile date in a single record

Try following code...

data want;

   input data_elaboration      8.

         filler1             $1.

         ch                  $1.

         filler2             $1.

         sw                  $1.

         filler3             $1.

         data_initialization 8.

         filler4             $1.

         data_fin            8

         filler5             $1.

         hour_ini            8.

         filler6             $1.

         hour_fin            8.

         filler7             $1. @@;

      cards4;

12345678 C T 12358789 12547898 20145789 4578912

;;;;

Hope it helps...

-Urvish

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 234 views
  • 1 like
  • 3 in conversation