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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 557 views
  • 3 likes
  • 2 in conversation