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.
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!
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.
Ready to level-up your skills? Choose your own adventure.