DATA Step, Macro, Functions and more

How to create a character variable with numbers in values gradually increase?

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

How to create a character variable with numbers in values gradually increase?

Hello,

 

I have a data set but without the study ID. In total there are 289 study subjects and I want to create a variable called "studyid" for each of them like this:

studyid

id-001

id-002

...

id-289.

 

I have searched many files but still cannot figure out the way. Does anyone can offer me some suggestions? Thank you!


Accepted Solutions
Solution
‎09-03-2017 07:40 PM
Super Contributor
Posts: 440

Re: How to create a character variable with numbers in values gradually increase?

Simple example

 

data class;
	length id $6;
	set sashelp.class;
	id=cat("id-",put(_n_,z3.));
run;

View solution in original post


All Replies
Solution
‎09-03-2017 07:40 PM
Super Contributor
Posts: 440

Re: How to create a character variable with numbers in values gradually increase?

Simple example

 

data class;
	length id $6;
	set sashelp.class;
	id=cat("id-",put(_n_,z3.));
run;
Contributor
Posts: 23

Re: How to create a character variable with numbers in values gradually increase?

Posted in reply to ChrisBrooks

Thank you Chris! That works perfectly!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 93 views
  • 0 likes
  • 2 in conversation