I need to use iterative processing to create a data set with one row per College, per year, per Category value. I set the values to missing in this step. With the following code, I can simulate the data set for just one level of the "Category" variable (the value 'PR'), but I can't seem to figure out how to do this for the other two levels of category. Something tells me that I need to find a way to process a loop within the loop, but I can't find a resource to help with that. Does anyone have any tips?
data colleges; *This college variable has seven levels.;
input college1 $;
cards;
ORG_A
ORG_B
ORG_C
ORG_D
ORG_E
ORG_F
ORG_G
;
RUN;
PROC SORT DATA=COLLEGES;
BY COLLEGE1;
RUN;
data simulation1;
SET COLLEGES;
BY COLLEGE1;
year = 2012;
do until (year = 2017);
year + 1;
CATEGORY = 'PR'; *This creates an output data set with 35 observations, but CATEGORY has two other levels, so I need a data set with 105 observations;
value = .;
output;
END;
RUN;
You're on the right track. Here are some slight changes:
data simulation1;
SET COLLEGES;
BY COLLEGE1;
value = .;
do year = 2012 to 2017;
do category='PR', 'AB', 'XY';
output;
end;
END;
RUN;
You will have to fill in the actual values for CATEGORY. Also, put the longest value first. The first value in the list determines how many characters get used to store CATEGORY.
****************** EDITED:
Needs a slight change. Should be: do year = 2013 to 2017;
How about providing something that actually looks like your input data and the desired output?
It is very likely that Proc Transpose will do what you want.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Here is the final output data set. This data set needs to be reproduced for two other levels of the variable Category.
ata WORK.SIMULATION1;
infile datalines dsd truncover;
input college1:$8. year:32. CATEGORY:$2. value:32.;
datalines4;
ORG_A,2013,PR,
ORG_A,2014,PR,
ORG_A,2015,PR,
ORG_A,2016,PR,
ORG_A,2017,PR,
ORG_B,2013,PR,
ORG_B,2014,PR,
ORG_B,2015,PR,
ORG_B,2016,PR,
ORG_B,2017,PR,
ORG_C,2013,PR,
ORG_C,2014,PR,
ORG_C,2015,PR,
ORG_C,2016,PR,
ORG_C,2017,PR,
ORG_D,2013,PR,
ORG_D,2014,PR,
ORG_D,2015,PR,
ORG_D,2016,PR,
ORG_D,2017,PR,
ORG_E,2013,PR,
ORG_E,2014,PR,
ORG_E,2015,PR,
ORG_E,2016,PR,
ORG_E,2017,PR,
ORG_F,2013,PR,
ORG_F,2014,PR,
ORG_F,2015,PR,
ORG_F,2016,PR,
ORG_F,2017,PR,
ORG_G,2013,PR,
ORG_G,2014,PR,
ORG_G,2015,PR,
ORG_G,2016,PR,
ORG_G,2017,PR,
;;;;
You're on the right track. Here are some slight changes:
data simulation1;
SET COLLEGES;
BY COLLEGE1;
value = .;
do year = 2012 to 2017;
do category='PR', 'AB', 'XY';
output;
end;
END;
RUN;
You will have to fill in the actual values for CATEGORY. Also, put the longest value first. The first value in the list determines how many characters get used to store CATEGORY.
****************** EDITED:
Needs a slight change. Should be: do year = 2013 to 2017;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.