BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nazmul
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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/

 

nazmul
Quartz | Level 8

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?

Reeza
Super User

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. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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