Reading raw datafiles

Reply
Occasional Contributor
Posts: 19

Reading raw datafiles

“HCA_file.txt” file contains different types of information for each Client_id, State, DoB in header row and different purchases carried out on different dates in transaction row. Import the data into SAS by retaining client_id and State such that i) Only transaction data is imported ii) Only header data is imported

Respected Advisor
Posts: 3,040

Re: Reading raw datafiles

Posted in reply to GAUTAMDVN

Show us your code.

--
Paige Miller
Occasional Contributor
Posts: 19

Re: Reading raw datafiles

Posted in reply to PaigeMiller

Hi Paige Miller,

 

I'm not able to find any relevant logic to write the statements to import the data into SAS because almost in every records there is different type of data but according to the query they've only ID, State, DOB and different purchases.

Super User
Posts: 23,754

Re: Reading raw datafiles

[ Edited ]
Posted in reply to GAUTAMDVN

It’s a well formatted file. There are two record types, C and H which appear consistent in the example posted. Search conditional input if you have no idea of where to start. 

 

 


@GAUTAMDVN wrote:

Hi Paige Miller,

 

I'm not able to find any relevant logic to write the statements to import the data into SAS because almost in every records there is different type of data but according to the query they've only ID, State, DOB and different purchases.


 

Occasional Contributor
Posts: 19

Re: Reading raw datafiles

Hi, please confirm why I'm wrong in the below code.

 

DATA X1;
INFILE HCA ;
INPUT ID $ @;
IF ID  = 'H' THEN INPUT CLIENT_ID STATE $ DOB : DATE7. ;
ELSE IF ID = 'C' THEN INPUT TRANSACTION_DATE : DATE7. PURCHASE : COMMA11.2;
FORMAT DOB transaction_date DATE9. PURCHASE DOLLAR11.2 ;
RUN ;
Super User
Posts: 23,754

Re: Reading raw datafiles

Posted in reply to GAUTAMDVN

What makes you think its wrong in the first place? If you have errors in your log post the log.

 


@GAUTAMDVN wrote:

Hi, please confirm why I'm wrong in the below code.

 

DATA X1;
INFILE HCA ;
INPUT ID $ @;
IF ID  = 'H' THEN INPUT CLIENT_ID STATE $ DOB : DATE7. ;
ELSE IF ID = 'C' THEN INPUT TRANSACTION_DATE : DATE7. PURCHASE : COMMA11.2;
FORMAT DOB transaction_date DATE9. PURCHASE DOLLAR11.2 ;
RUN ;

 

Occasional Contributor
Posts: 19

Re: Reading raw datafiles

Hi,

The code is correct as per attachment but not able to import the data into SAS by retaining only client_id and State such that A. only transaction data is imported  B. only header data is imported

Super User
Posts: 23,754

Re: Reading raw datafiles

Posted in reply to GAUTAMDVN

The data is being read in correctly. You have not accounted for the fact that you want to retain the header information across the rows. You can look into RETAIN to hold values until you need to reset it. Please post your code and output directly into the forum rather than as attachments.

 


@GAUTAMDVN wrote:

Hi,

The code is correct as per attachment but not able to import the data into SAS by retaining only client_id and State such that A. only transaction data is imported  B. only header data is imported


 

 

 

 

 

 

Super User
Posts: 23,754

Re: Reading raw datafiles


@Reeza wrote:

The data is being read in correctly. You have not accounted for the fact that you want to retain the header information across the rows. You can look into RETAIN to hold values until you need to reset it. Please post your code and output directly into the forum rather than as attachments.

 


@GAUTAMDVN wrote:

Hi,

The code is correct as per attachment but not able to import the data into SAS by retaining only client_id and State such that A. only transaction data is imported  B. only header data is imported


 

 

 

 

 

 


Screen Shot 2018-06-17 at 1.42.05 PM.pngScreen Shot 2018-06-17 at 1.42.22 PM.png

Ask a Question
Discussion stats
  • 8 replies
  • 146 views
  • 0 likes
  • 3 in conversation