BookmarkSubscribeRSS Feed
kippy_kips
Calcite | Level 5

I have columns named dairy_ee, fruit_ee, oils_ee, etc. They are either a 0 or 1 but there are some blank spaces. I want to fill these columns with a 0 or 1 based on another variable group.

It looks something like this:

Groupdairy_eefruit_eeoils_ee
1010
1...
2010
2...
3110
3...
4000
4...
4...

Thank you!

5 REPLIES 5
mkeintz
PROC Star

@kippy_kips wrote:

I have columns named dairy_ee, fruit_ee, oils_ee, etc. They are either a 0 or 1 but there are some blank spaces. I want to fill these columns with a 0 or 1 based on another variable group.

And what is the specific relationship between the variable group and the intended blank-replacement values?  That is what is the rule you want to applhy?

 

 

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
kippy_kips
Calcite | Level 5
I want each empty to be filled with the 0 or 1 that is already in that group
Astounding
PROC Star
Here's a program that will work based on the limited amount of data shown:

dara want;
update have (obs=0) have;
by group;
output;
run;

It requires that the incoming data is sorted by GROUP, and that a GROUP never begins with a blank row.
kippy_kips
Calcite | Level 5
I have other columns that I don't want to fill blanks in, can you specify columns?
Astounding
PROC Star
Yes, but you will need to add a statement to the program that controls which variables don't get replaced. Just before the OUTPUT statement:

set have (keep = list of variables to keep as is);

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 5 replies
  • 1675 views
  • 0 likes
  • 3 in conversation