BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jc3992
Pyrite | Level 9
data temperature;
infile '/folders/myfolders/Programs/tempArray.csv' dlm=',' dsd missover;
input temperatureC 2.1;
temperatureF = temperatureC*(9/5)+32;
run;

Hello everyone,

I attached the original data and I wonder if anyone would like to give me some guide on how to read in the whole data?

The log did not show any errors but there is 120 data in it so my output is not correct.

 

Thanks much!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The informat is incorrect:

 

input temperatureC 2.1;

 

Instead, it should be:

 

input temperatureC 4.;

 

The width of 4 tells SAS to read 4 characters, and interpret whatever is there as a numeric value.

 

Instructions of 2.1 would not do the job.  That tells SAS to read only 2 characters, and if they contain no decimal point to assume that the last of those characters should be placed after the decimal point.

View solution in original post

6 REPLIES 6
Reeza
Super User

Are you trying to read all into one column? You have 24 columns but you've only listed one variable in the INPUT statement. 

If you're unsure of the type/formats import it first using PROC IMPORT with GUESSINGROWS=MAX and then use the code from the log. 

 


@jc3992 wrote:
data temperature;
infile '/folders/myfolders/Programs/tempArray.csv' dlm=',' dsd missover;
input temperatureC 2.1;
temperatureF = temperatureC*(9/5)+32;
run;

Hello everyone,

I attached the original data and I wonder if anyone would like to give me some guide on how to read in the whole data?

The log did not show any errors but there is 120 data in it so my output is not correct.

 

Thanks much!


 

Astounding
PROC Star

The informat is incorrect:

 

input temperatureC 2.1;

 

Instead, it should be:

 

input temperatureC 4.;

 

The width of 4 tells SAS to read 4 characters, and interpret whatever is there as a numeric value.

 

Instructions of 2.1 would not do the job.  That tells SAS to read only 2 characters, and if they contain no decimal point to assume that the last of those characters should be placed after the decimal point.

jc3992
Pyrite | Level 9

Thank you it works.

But there is only 6 obs. in Temp C and temp F

why would this happen?

data temperature; 
infile '/folders/myfolders/Programs/tempArray.csv' dlm=',' dsd; 
input temperatureC 4.; 
temperatureF = temperatureC*(9/5)+32; 
run; 
 
proc print data=temperature; 
run; 
Reeza
Super User

Because you have 24 variables and 5 rows of data, but your code is set up to read one variable. 

And since you didn't specify FIRSTOBS=2 it assumed the first row (header row) was data not a header. 

 

 

 

 

 

jc3992
Pyrite | Level 9

got you!

 

But I added a "@@" behind it would not work.

data temperature; 
infile '/folders/myfolders/Programs/tempArray.csv' dlm=',' dsd firstobs=2; 
input temperatureC 4.; 
temperatureF = temperatureC*(9/5)+32; 
run; 
 
proc print data=temperature; 
run;
novinosrin
Tourmaline | Level 20

@Reeza was brilliant to ask even what's your exact requirement as I am confused whether you seek clarification on how informats work or the right informats to apply or a code help to read your array data. If its the latter, here you go-

 

data temperature;
infile 'C:\Users\NSRINIV2\Documents/tempArray.csv' dlm=',' dsd missover firstobs=2;
input temperatureC @;
do while(not missing(temperatureC));
temperatureF = temperatureC*(9/5)+32;
output;
input temperatureC @;
end;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 6 replies
  • 791 views
  • 4 likes
  • 4 in conversation