BookmarkSubscribeRSS Feed
9 REPLIES 9
Reeza
Super User
You don't specify a delimiter, what's your delimiter?
Srivikasheeba
Calcite | Level 5
. ..
Reeza
Super User
Are you reading from a text file or CARDS?
Srivikasheeba
Calcite | Level 5

I am reading csv files using infile statement 

Reeza
Super User
How are you currency values specified in the CSV? They have comma's embedded in the field, but I assume they have quotation marks around them? If not, how do you know if a value is $123 or $123,456? In this case you'd have an improperly specified CSV file which would be difficult to work with. You need to verify your CSV with a text editor or SAS, not Excel. Excel 'imports' data to view it and it may not reflect the true data.
Reeza
Super User

From what you've shown initially this works. It seems like your actual problem may be a bit different, in that case this may or may not work.

 

data have;
informat cumulative_premium dollar. medical_expenses dollar. renewaldt mmddyy10.;
format cumulative_premium medical_expenses dollar12. renewaldt date9.;
input Cumulative_premium Medical_Expenses Renewaldt;
cards;
$123,456       $456,876                            3/1/2019
$786,000       $657,999                            3/1/2019
$786,909       $678,000                            3/15/2019
;;;;
run;

proc print data=have;
run;

@Srivikasheeba wrote:

infile "path";

ENCODING = "LATINI"

PAD

DLM=' , '

MISSOVER

DSD FIRSTOBS=2;

This is my code before length statement


 

Srivikasheeba
Calcite | Level 5

Hello reeza ,thanks for the reply, date9. just changed the date format but the error still persists , now my date value is 

01JAN2019

but the secound date is still missing and this is read .9 in next column, where it shouldnt read

Renewaldt      Rent

01JAN2019 
                    . 9

 

problem is program not reading correctly the dates 

date 1:1/1/2019

date2:1/15/2019

if i give mmddyy8. only 1/1/2019 reads but other date moves to rent column and reads as .9 (which is the 9 in 2019)

if I give mmddyy9. only 1/15/2019 reads but date1 is missing

how can I read both @ once?

 

ballardw
Super User

Here's an idea, show use some of your actual lines of data. Copy the lines with the header and maybe 5 lines of data. On the forum open a text box using the </> icon and paste the data.

BTW, if you opened the file in a spreadsheet and then saved on closing you may have just changed the original contents of the cells.

 

Or copy the log from running or code for the entire step reading the data including all notes and warnings and again paste into a text box.

The message windows reformat text quite a bit.

 

;

Input
Cumulative premium$ 
Medical Expenses$ 
Renewaldt ANYDTDTE10.

;

would attempt to read in 5 variables: Cumulative (as numeric), premium as character, Medical (as numeric), Expenses as character and then the Renewaldt. If the source is as you describe then by the time you get to Medical all of the data columns have been "used" and then Expenses and Renewaldt should generate the ever popular "read on next line" warning.

 

Standard SAS variable names cannot have spaces in them. If you want to use "extended" names and the system options are set to allow it you would have to use "Cumulative Premium"n to reference a single variable. The quotes and n needed every place you attempt to use the variable.

Kurt_Bremser
Super User

What you posted is positively NOT a csv file at all. In Comma Separated Volumes, data items have to be separated by commas, not arbitrary numbers of blanks.

Open your file with a text editor (NOT with Excel!), copy the first few lines, and paste them into a code box opened with the </> button. Do not skip this.

Only when we can see your real data will we be able to help you.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1504 views
  • 0 likes
  • 4 in conversation