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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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