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

This is the dataset - it comes in like this automatically. And the number of rows per hospital changes each month so this is not something I want to manually code each month by saying "if it's rows 1:6 then hospital name = Hospital A". Again, the number of rows per hospital changes monthly.

 

Is there an array or something that we can do so that "Hospital Name" gets populated with the correct hospital name by saying fill it in with Hospital A until there is no longer a blank, then fill it in with the next name?

 

Hospital Name          Month

Hospital A                  Jan

                                  Feb

                                  March

                                  April

                                  May

                                  June

Hospital B                 Jan

                                 Feb

                                 March

Hospital C                 Jan

                                 Feb

                                March

                                April

 

This is what I want:

 

Hospital Name         Month

Hospital A                  Jan

Hospital A                  Feb

Hospital A                  March

Hospital A                  April

Hospital A                  May

Hospital A                  June

Hospital B                  Jan

Hospital B                  Feb

Hospital B                  March

Hospital C                 Jan

Hospital C                 Feb

Hospital C                 March

Hospital C                 April

 

Any insight would be appreciated!

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;

retain HospitalID;
if not missing(FAC_ID) then HospitalID=FAC_ID;

run;

Those are the two lines you need.

 


@Krysia24 wrote:

Comes to us as a SAS dataset. Hospital Name is actually "FAC_ID." I did not include the rest of the variables for simplicity but let me know if that's helpful.


 

 

View solution in original post

4 REPLIES 4
Reeza
Super User
You want RETAIN not an array.
Astounding
PROC Star

This task is relatively easy, but you need to give us information about the data.

 

"This is the dataset" ==>  Is this a SAS data set?  If not, where is the program that reads it into SAS?

 

If this is a SAS data set, what are the variable names?  (Do you really have a variable named "Hospital Name" with a blank in the middle of the name?)  Does it contain other variables that you haven't shown?  (Yes, that makes a difference in terms of which solutions will work properly.)

Krysia24
Obsidian | Level 7

Comes to us as a SAS dataset. Hospital Name is actually "FAC_ID." I did not include the rest of the variables for simplicity but let me know if that's helpful.

Reeza
Super User
data want;
set have;

retain HospitalID;
if not missing(FAC_ID) then HospitalID=FAC_ID;

run;

Those are the two lines you need.

 


@Krysia24 wrote:

Comes to us as a SAS dataset. Hospital Name is actually "FAC_ID." I did not include the rest of the variables for simplicity but let me know if that's helpful.


 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1372 views
  • 1 like
  • 3 in conversation