12-02-2014 03:16 PM
hi hi I want to add leading zeros to numeric fields and the docurgent the format is I3
tthat is Integer 3 it means when age is 36 we don't need to add leading zeros because 36 is 2 bytes and +sign occupies 1byte
but when age is 8 then add one leading zero . Can anybody suggest
12-02-2014 03:40 PM
Sounds like you need a PICTURE format:
picture this low-high='99' (prefix='+');
Then when printing a variable, add:
format varname this3.;
12-03-2014 10:18 AM
i have used Newage= put(input(old_age,best2.),z2.); I gave me leading zeros
but when I am exporting data to csv file I am missing leading zeros
data in Csv file
can any one pls help me .
12-03-2014 11:03 AM
The zeros are in the CSV file, but you are probably opening the file in Excel and it is converting them back to a number.
Open the CSV file with a text editor and you will see the zeros.
12-03-2014 11:33 AM
Open your .csv file with a text editor like Notepad and check if you can see the zeros this way. If so then Tom's assumption is confirmed and we can discuss of how to write strings of digits to a .csv file so that when opening it in Excel digit strings don't get converted into numbers.
12-02-2014 04:25 PM
Just for having leading zero's for numeric variables you can use the out-of-the-box Zw.d format for this. SAS(R) 9.4 Formats and Informats: Reference
I'm not really sure what you're trying to explain with the bytes. I would have thought that for numeric variables the +/- consumes one bit only (and not a byte).
If you're dealing with character variables then please provide some representative sample data and then explain how the result should look like.
12-04-2014 12:36 PM
FFirst age variable in dataset is numeric with length 8
then I changed like this
data x (drop= age);
old_age= put( age,2.);
then in another data step i converted to
i have used Newage= put(input(old_age,best2.),z2.); I
whren I am exporting to Csv. I don't c any leading zeros And in document.
AGe. Format. I3. I3 = Integer 3 so what format new age should be numeric or character
12-04-2014 01:04 PM
How are you making the CSV file?
You can read the CSV file with a data step and dump the lines to the SAS log to see if there are leading zeros. For example this program will show the first 10 lines.
infile 'myfile.csv' obs=10 ;
If the column is intended to be integer then why do you want leading zeros?
Also the column is specified as length 3 so why are you not using Z3 format? Age should not be negative. People do live to be over 99 years old.
12-04-2014 01:10 PM
I Didn't understand what u you have said
i have not used z3 because for EG
i want only
but if I use z3
the he output will be
but in I3 format one byte will be for sign and other two for digits
12-04-2014 01:29 PM
How did you generate a CSV file from the SAS dataset? Did you call PROC EXPORT? Did you use ODS CSV ? Did you use a data step with DSD option on the FILE statement? Did you use some functionality of Enterprise Guide?
Why do you think that you need a leading zero? What software are you planning to use the resulting CSV file with that would require the leading zero?
Perhaps you just need to explicitly include the sign into the new character variable?
char_age = cats('+',put(age,z2.)) ;
What system is defining I3 to mean sign plus two digits? I3 looks like a FORTRAN format specification and the sign is not required, but takes up one of the characters if present. So '001' would be valid and so would '+01' or '-01'. But '-101' would be too long since it would require 4 characters instead of three.
Are you sure that you even want a CSV file? If your data definition is explicitly listing the number of columns for each variable then perhaps you want to generate a fixed field file instead of a comma separated file?
12-04-2014 02:30 PM
HHi tom ,
to age variable I used the syntax u gave me the result is
i am using SAS EG I am exporting SAS dataset using export to in SaS EG and saving in my c drive as a Csv file