BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
nnthieu
Fluorite | Level 6

Truncation of character variables to 8 when import csv file from website using code as follow. If I set 'sales_method' $12. then it read some characters from the next column. Please help me. Thanks

 

filename tempurl TEMP;

proc http
url= "https://s3.amazonaws.com/talent-assets.datacamp.com/product_sales.csv"
method="get"
out=tempurl ;
run;

 

/* Import the data from the URL into a SAS dataset */
data work.sales;
infile tempurl dlm =',' dsd firstobs=2 truncover ; /* Set delimiter and skip header row */
input week $ sales_method $ customer_id $ nd_sold revenue
years_as_customer nb_site_visits state $ ;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
SASJedi
SAS Super FREQ

All new variables created by the INPUT statement will have a length of 8 by default. Use informats on the INPUT statement to override the default and set the length values you need:

filename tempurl TEMP;

proc http
   url= "https://s3.amazonaws.com/talent-assets.datacamp.com/product_sales.csv"
	method="get" out=tempurl;
run;


/* Import the data from the URL into a SAS dataset */
options errors=0; /* Suppress invalid data log entries whe REVENUE values are "NA" */
data work.sales;
	infile tempurl dlm =',' dsd firstobs=2 truncover ; /* Set delimiter and skip header row */
	/* Supplay informats on the input statement to set variable lengths */
	input week:best32.  sales_method:$12.  customer_id:$36.  nb_sold:best32. revenue:best32. 
	years_as_customer:best32.  nb_site_visits:best32.  state:$13.  ;
run;
options errors=20; /* Restore default setting */

Check out my Jedi SAS Tricks for SAS Users

View solution in original post

2 REPLIES 2
SASJedi
SAS Super FREQ

All new variables created by the INPUT statement will have a length of 8 by default. Use informats on the INPUT statement to override the default and set the length values you need:

filename tempurl TEMP;

proc http
   url= "https://s3.amazonaws.com/talent-assets.datacamp.com/product_sales.csv"
	method="get" out=tempurl;
run;


/* Import the data from the URL into a SAS dataset */
options errors=0; /* Suppress invalid data log entries whe REVENUE values are "NA" */
data work.sales;
	infile tempurl dlm =',' dsd firstobs=2 truncover ; /* Set delimiter and skip header row */
	/* Supplay informats on the input statement to set variable lengths */
	input week:best32.  sales_method:$12.  customer_id:$36.  nb_sold:best32. revenue:best32. 
	years_as_customer:best32.  nb_site_visits:best32.  state:$13.  ;
run;
options errors=20; /* Restore default setting */

Check out my Jedi SAS Tricks for SAS Users
nnthieu
Fluorite | Level 6

It works. Excellent !. Thank you so much.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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