BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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
1 ACCEPTED SOLUTION
5 REPLIES 5
SASdevAnneMarie
Barite | Level 11
Thank you, Kurt!
Kurt_Bremser
Super User

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

  • download the file
  • upload it to my ODA account
  • run PROC IMPORT, with no guarantee that the resulting dataset looks like yours

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.

SASdevAnneMarie
Barite | Level 11
OK Kurt,
Thank you !
ballardw
Super User

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

How to Concatenate Values

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 131 views
  • 1 like
  • 3 in conversation