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!
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.
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.)
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.