Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

Accepted Solution Solved
Reply
Contributor
Posts: 66
Accepted Solution

Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

Hi, I want to change all missing values from the year 1982 to 1988 to 0, but I want to keep data from 1980 to 1981 and from 1989 to 1991 unchanged. I just put income variable here but my original data set has 45 variables. I want to apply the change to all the variables. Could anyone please help me?

 

Picture1.png


Accepted Solutions
Solution
‎05-20-2017 03:34 PM
Super User
Posts: 19,167

Re: Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

[ Edited ]

Please do not post data as an image. To use your data we would have to type it out, which you should really do ahead of time. 

There are instructions here on how to post your data. 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Your question is a conditional execution. 

 

So your conditions appear to be:

 

If year Greater than or equal to 1982 and year less than or equal to 1988

    If income is missing then set income to 0

Else do nothing

 

If this is correct you can convert it to code via:

*If year Greater than or equal to 1982 and year less than or equal to 1988;
if year >= 1982 and year <= 1998 then do;
    *If income is missing then set income to 0;
     if income = . then income=0;
*else do nothing;
end;

To incorporate multiple values you would need an array. 

To create an array you need to list all the variables somehow and they need to be the same type. 

I would suggest giving the expansion a try yourself and posting back if you have issues:

Here's a tutorial:

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

View solution in original post


All Replies
Solution
‎05-20-2017 03:34 PM
Super User
Posts: 19,167

Re: Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

[ Edited ]

Please do not post data as an image. To use your data we would have to type it out, which you should really do ahead of time. 

There are instructions here on how to post your data. 

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

Your question is a conditional execution. 

 

So your conditions appear to be:

 

If year Greater than or equal to 1982 and year less than or equal to 1988

    If income is missing then set income to 0

Else do nothing

 

If this is correct you can convert it to code via:

*If year Greater than or equal to 1982 and year less than or equal to 1988;
if year >= 1982 and year <= 1998 then do;
    *If income is missing then set income to 0;
     if income = . then income=0;
*else do nothing;
end;

To incorporate multiple values you would need an array. 

To create an array you need to list all the variables somehow and they need to be the same type. 

I would suggest giving the expansion a try yourself and posting back if you have issues:

Here's a tutorial:

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

Contributor
Posts: 66

Re: Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

Thank you for your help. Regarding my impage upload, I am sorry I did not know the rule. Should I upload a SAS file instead from next time?

Super User
Posts: 19,167

Re: Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

Don't upload any files. 

In the future use the instructions in the post linked to create a data step so someone can recreate your dataset via a program. This means there's no risk of downloading an infected file. 

Contributor
Posts: 66

Re: Replace all missing values of specific years in a panel data to 0 (not all missing values to 0)

Thank you for your suggestion. I will do

☑ This topic is solved.

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

Discussion stats
  • 4 replies
  • 135 views
  • 0 likes
  • 2 in conversation