Write and run SAS programs in your web browser

raw data file problem

Reply
Contributor
Posts: 26

raw data file problem

Problem Statement :- 

 

  1. “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

 

DATA :-

 

Data Containing Headers Denoted with "D" and Transactions is  denoted as "C"

H 1097 VG 07JUL74
C 01FEB11 $109.5
H 1099 OT 13FEB79
C 01Mar11 $45.0
C 01May11 $45.0

 

kindly help Smiley Happy

 

Super User
Posts: 11,343

Re: raw data file problem

Since this looks an awful lot like a homework assignment I'm not going to provide a full solution but some hints.

 

One is read the entire line as text. SAS creates an automatic variable called _INFILE_ when any Input statement is executed.

You can parse the values from the line conditionally by examining the first character of infile:

 

if _infile_ =: 'H' then do;

<something>

end;

if _infile_ =: 'C' then do;

<something>

end;

The Retain statement will indicate variables to keep values from one interation of the data step to the next.

SCAN can pull out space delimited items from the text.

An explicit Output statement when the data is type C will result in combined H and C data if the read and parse is done correctly.

 

Contributor
Posts: 26

Re: raw data file problem

no its not a homework.....i am learning SAS on my own and got all these problem statements and data from one of my friend who did this course but he is in Japan now and i am working on these problem to solve it.

Super User
Super User
Posts: 7,063

Re: raw data file problem


jonty wrote:

no its not a homework.....i am learning SAS on my own and got all these problem statements and data from one of my friend who did this course but he is in Japan now and i am working on these problem to solve it.


Try the ideas that @ballardw posted and either post the resulting working code (and mark it as the solution) or post what you have tried and ask a more detailed question.

Super User
Posts: 11,343

Re: raw data file problem


jonty wrote:

no its not a homework.....i am learning SAS on my own and got all these problem statements and data from one of my friend who did this course but he is in Japan now and i am working on these problem to solve it.


Actually I would say this is self-assigned homework. Smiley Happy

 

I'm sure that we could post a variety of solutions, some that are on the esoteric side of coding options, between the users here.

I suggested some keywords you can search in the help that will lead to knowing where to find things that will help learn some SAS basics.

 

I find that I learn much better when attempting something, and frequently not getting right the first time. There are a number of things I can see with that example that might be potential issues but if you get something that works partially then it is likely that explainations on the solution will mean a bit more. Or you may surprise yourself as @Tom mentions and get the whole solution.

 

The online help is usually quite good in SAS compared to a number of other software vendors. So it is worth while learning to use it.

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 263 views
  • 2 likes
  • 3 in conversation