Solved
Contributor
Posts: 26

# How to put a certain value to all values in a variable?

[ Edited ]

Hello,

I have a dataset where people's birth years and months are recorded.

I want to assume that each person was born on the first date of each month.

e.g) Someone born in April of 1980->April 1st, 1980

``````data one;
input ID \$ birth_ym;
cards;
1 198004
2 199712
3 200207
;
run;``````

I would want to create a variable that has '01' added to the end for each value of birth_ym

198004->19800401

199712->19971201

200207->20020701

So, I would want a variable to include

birthday_new

19800401

19971201

20020701

Is there a simple way to solve this problem?

Thank you.

Accepted Solutions
Solution
‎04-02-2018 07:50 AM
Regular Learner
Posts: 1

## Re: How to put a certain value to all values in a variable?

Can you read the existing month/year date value as a character string? If so, then this will work:

data one (keep=ID birthday_new);
length ID \$7 birth_ym \$6;
input ID \$ birth_ym \$;
birthday_new = input( birth_ym || '01',  yymmdd8.);
format birthday_new date10.;
cards;
1 198004
2 199712
3 200207
;
run;

All Replies
PROC Star
Posts: 1,836

## Re: How to put a certain value to all values in a variable?

Do you mean you are looking for

YYMMNw. Informat

Reads date values in the form yyyymm or yymm.

``````data one;
input ID \$ birth_ym : yymmn6.;
format 	birth_ym date9.;
cards;
1 198004
2 199712
3 200207
;
run;``````
Solution
‎04-02-2018 07:50 AM
Regular Learner
Posts: 1

## Re: How to put a certain value to all values in a variable?

Can you read the existing month/year date value as a character string? If so, then this will work:

data one (keep=ID birthday_new);
length ID \$7 birth_ym \$6;
input ID \$ birth_ym \$;
birthday_new = input( birth_ym || '01',  yymmdd8.);
format birthday_new date10.;
cards;
1 198004
2 199712
3 200207
;
run;

Super User
Posts: 6,785

## Re: How to put a certain value to all values in a variable?

You should study how SAS stores dates.  Dates are much more useful when stored in the form that SAS expects.  These are numeric variables, not dates.

That being said, converting y our numbers to different numbers is relatively straightforward:

birthdate = birth_ym * 100 + 1;

If you wanted to convert these values to the form that SAS expects, you could add after this equation:

birthdate = input(put(birthdate, z8.), yymmd8.);

format birthdate yymmdd10.;

But dates in the "correct" form may not be useful to  you until you understand what they contain.

☑ This topic is solved.