Hello Experts,
I have a data ID_F and F (in numeric format), I would like to put the ID_F in format 0000 and F in 000 format.
Do you know how to do it easily beacause I apply Repet function with IF THEN ELSE condition. Maybe there is some format statement ? I joined the data. Thank you for your help !
ID_F (numeric) | F (numeric) | ID_F-F (character) |
73 | 1 | 0073-001 |
83 | 2 | 0083-002 |
45 | 4 | 0045-004 |
1 | 23 | 0001-023 |
453 | 23 | 0453-023 |
id_f_f = catx("-",put(id_f,z4.),put(f,z3.));
id_f_f = catx("-",put(id_f,z4.),put(f,z3.));
For the future: do not bother to attach Excel files.
Many of us won't (or even can't, for security reasons) download Office files.
Excel spreadsheets do not have the concept of fixed column attributes.
I would have needed to
For simple issues (like this here), the values and description are sufficient. For more complex issues, post DATA step code (with DATALINES), so we can exactly recreate your dataset with simple copy/paste and submit. It's less work for you and for us.
Suggestion: your subject line should read something like "create character variable from numeric values".
Please avoid the use of the word "Format" unless you mean a SAS Format. Format has very specific meaning in SAS related to display of values. Run Proc Contents on any of your data sets and you will see the Format is property of variables.
For instance the Format to display a numeric value with a fixed number of characters and leading zeroes is the Zw.d format where W is the number of characters and D is the number of decimal positions to show.
A format of Z4. will display an integer value with 4 characters padding leading zeroes as needed.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.