BookmarkSubscribeRSS Feed
asuman
Obsidian | Level 7

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;

4 REPLIES 4
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
asuman
Obsidian | Level 7

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..
Reeza
Super User

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.

ballardw
Super User

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.

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!

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.

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
  • 712 views
  • 0 likes
  • 4 in conversation