DATA Step, Macro, Functions and more

problem infile statement

Reply
Occasional Contributor
Posts: 5

problem infile statement

I converted xls file into txt and then i wrote a code to infile that file but i am not getting results and the log windows is showing garbage values.

 

data online;
infile "/folders/myfolders/OnlineShopping.txt"
firstobs=2;
input C_ID Product_ID P_CATEGORY $ CONDTION $ Brand $ Price Selling_price;
run;
title 'online shopping';
proc print data=online;
run;

Trusted Advisor
Posts: 1,913

Re: problem infile statement

So, if you're not getting the results you want, and you also want our help, we'd need to see the input data (or a relevant portion of it) as well as the output results that aren't what you want.

Occasional Contributor
Posts: 5

Re: problem infile statement

Posted in reply to PaigeMiller

input data(small portion of the whole data)

C_IDProduct_IDP_CATEGORYCONDTIONBrandPriceSelling_price
4595534SHOESNewRKFCM$1,484.74$1,471.74
6679396LUGGAGENewTNVON$1,452.50$1,442.50
7075449SHOESRefurbishedVKKEA$4,308.02$4,284.02
1418145BEDDINGNewPIUEM$3,272.59$3,249.59
6740844ELECTRONICSUsedFMBZC$628.67$608.67
4305922LUGGAGENewIWPJG$3,788.97$3,740.97

 

the wrong output 

 

  Obs C_ID Product_ID P_CATEGORY CONDTION Brand Price Selling_price 1 2 3 4 5 6 7

..card 3046679 396carrier..
..Sports Mcard 5866740 844..
..HardwarecarrierBilling..
..5974 470card 2887759 266..
..NorthFace GH6carrier..
..carrierBilling3723 710..
..carrierBilling6565 396..
Super User
Posts: 19,782

Re: problem infile statement

Try using a PROC IMPORT instead. Set the GUESSINGROWS option to the number of rows that you have. 

The log will have the data step code that you need and you can compare it to your non-working code.

Super User
Posts: 11,343

Re: problem infile statement

Unexpected output? Provide input data in the form of an attached text file or just pasted into a code box, the actual results and the expected results.

 

I would suggest that saving as CSV would be a better choice than TXT as you may end up with tab delimited and your code doesn't show any delimeter. I would expect not to get the desired result. With the CSV try using the import wizard or proc import and then examine the datastep code that will appear in the log. I often then copy the code from the log and modify where needed to allow longer variables, change things that appear to be numeric but should be character or the other way around and such.

Ask a Question
Discussion stats
  • 4 replies
  • 93 views
  • 0 likes
  • 4 in conversation