if a variable contain dates like "2015/01"---"2015/12" (yymm) ,How to add day to those dates,if them month is jan then 31 if the month is feb then 28 so on ...



if a variable contain dates like "2015/01"---"2015/12" (yymm) ,How to add day t..

Answer / Sona Singh

In SAS, you can create a dataset with the days for each month and then merge it with your original dataset. Here's an example:

```sas
data days;
do month = 1 to 12;
if (month = 2) then
days = 28;
else if ((month mod 4) = 0 and (month > 2)) then
days = 29;
else if (month in (1, 3, 5, 7, 8, 10, 12)) then
days = 31;
else
days = 30;
output;
end;
run;

data work.your_dataset;
merge your_dataset (rename=(date=from_date)) days;
set your_dataset;
date = mdys(year(from_date), month(from_date), day('01'd + ifn(month,31,28) + ifn(leap_year,1)));
run;
```
In this example, `leap_year` is a variable that indicates whether the year in `from_date` is a leap year.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More SAS Interview Questions

What are the criticality that you have faced during your project in SAS?

2 Answers  


i want for interview question & answer plz it need immediate send t my mail raviprakashmot@gmal.cm

1 Answers   SAS,


What system options would you use to help debug a macro? : sas-macro

1 Answers  


what is program data vector? : Sas-administrator

1 Answers  


What are the functions done while Compilation...?

1 Answers   TCS,


How would you code a merge that will write the matches of both to one data set, the non-matches from the left-most data?

1 Answers  


How do you control the number of observations and/or variables read or written? Approximately what date is represented by the SAS date value of 730?

1 Answers   Quintiles,


What are the applications primarily used by business analyst? : Sas-bi

1 Answers  


Mention sas system options to debug sas macros.

1 Answers  


what is function of retain statment

1 Answers   PPD,


What SAS statements would you code to read an external raw data file to a DATA step?

6 Answers   Accenture,


how to import HTML files into SAS datasets?

3 Answers   HP,


Categories