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;
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 */
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 */
It works. Excellent !. Thank you so much.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.