Reputation: 55
I write the code in SAS enterprise guide 8.3, and find there is space in the name of the file. Anyone knows why? please reference the attached screenshot for details. The space is after the character "Y_2021"; Thanks
Upvotes: 0
Views: 328
Reputation: 51621
SAS has two types of variables. Floating point numbers and fixed length character strings.
You have not explicitly set the types or lengths of any of the variables, so SAS must decide how to define them based on how they are first used in the code. Since TODAY1 is getting the results of PUT() function using a format of width 8 it will be defined as length $8. And since they other variables are first seen as the result of functions operating on TODAY1 they will also be defined as length $8.
So the TRIM() function calls in your second and third assignment statement are doing nothing. It removes the trailing spaces and then stores the value back into a fixed length variable which means that value is padded out to 8 bytes again.
You could define the variables before using them.
length today1 $8 year1 $4 ;
You could also create the variables with statements that you are sure will cause SAS to define the length to what you need.
today = today();
year = put(today,year4.);
dateyyyymmdd = put(today,yymmddn8.);
If you do need to concatenate variables that could have short values then add the TRIM() function calls into the place where you need to trimmed values. Or better still use the CATS() function instead of the concatenation operator.
Upvotes: 0
Reputation: 12909
year1
is being padded with spaces by the concatenation operator. It is a a better practice to use cats
, catt
, or catx
rather than the ||
operator for concatenation. These functions ensure that the values being concatenated are not padded.
Use the code below instead.
csvfile_temp = cats('Y_', year1, '0101_', dateyyyymmdd, '.csv');
Upvotes: 1