DATA Step, Macro, Functions and more

how to replace an ID variable (convert from numeric into character)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

how to replace an ID variable (convert from numeric into character)

Hello everyone,

 

I have a file and its first variable is an ID variable that is numeric, when it should be character. If I convert it and rename it, the new variable is placed at the end of the file, which is cumbersome. I tried using "retain" to reorder the file, but somehow the ID variable remains at the end (not sure what I do wrong). Is there an easier way of doing this?

 

ThanksSmiley Happy


Accepted Solutions
Solution
‎02-17-2017 03:15 PM
PROC Star
Posts: 7,366

Re: how to replace an ID variable (convert from numeric into character)

To reorder the variables the retain statement has to come BEFORE the set statement.

 

HTH,

Art, CEO, AnalystFinder.com

View solution in original post


All Replies
Solution
‎02-17-2017 03:15 PM
PROC Star
Posts: 7,366

Re: how to replace an ID variable (convert from numeric into character)

To reorder the variables the retain statement has to come BEFORE the set statement.

 

HTH,

Art, CEO, AnalystFinder.com

Occasional Contributor
Posts: 11

Re: how to replace an ID variable (convert from numeric into character)

Hi, thank you so much for your answer! Best regards

Trusted Advisor
Posts: 1,406

Re: how to replace an ID variable (convert from numeric into character)

Use next skiltom code:

 

data want;

         format id;   /* force ID to be 1st , you can add other variables in desired order*/

  set have(rename=(id=_id));

        ID = input(_id, best8.);    /* adapt to length of ID */

run;

Occasional Contributor
Posts: 11

Re: how to replace an ID variable (convert from numeric into character)

Thank you so much! Best regards!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 133 views
  • 2 likes
  • 3 in conversation