BookmarkSubscribeRSS Feed
jonty
Fluorite | Level 6

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 🙂

 

4 REPLIES 4
ballardw
Super User

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.

 

jonty
Fluorite | Level 6

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.

Tom
Super User Tom
Super User

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

ballardw
Super User

@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. 🙂

 

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.

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1028 views
  • 2 likes
  • 3 in conversation