I have a similar problem, so I was happy to find this post! However, mine is a little bit different since I want to extra rows to be blank except for the identifier column. For example, starting with Table HAVE:
Name | Date | Data Columns |
---|---|---|
A | Jan | X |
A | Feb | Y |
A | Feb | Z |
B | Jan | A |
I'm trying to get to Table WANT:
Name | Date | Data Columns |
---|---|---|
A | Jan | X |
A | Jan | . |
A | Feb | Y |
A | Feb | Z |
B | Jan | A |
The second row in Table WANT is the "inserted row" with missing values in the Data Columns. Using your code and a column that indicates when and how many rows to insert, I can insert the wanted extra row but the value in Data Columns is X. Now I want to set X to missing, but only for the added row.
Help?
Since I have the ready-to-go sample set from polingjw , only a minor change to his/her code will do.here is what I came up with:
data have;
input no part $ qty;
datalines;
1 A100 2
5 B100 3
25 A100 1
35 B100 2
;
run;
data want(keep=no part qty);
set have(rename=(qty=oldqty));
retain qty 1;
do _n_=1 to oldqty;
part=ifc(_n_=1,part,'');
output;
end;
run;
proc print;run;
Regards,
Haikuo
On the code where you are adding the row follow with something like "VAR = .;" before the additional output.
I suspect you have a logical condition being and if you are useing an IF - THEN structure to create the additional row you may need to use a DO - END to get the assignment in right place. If you have a lot of variables an array could be used.
An example of your almost working code would provide a better start point.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.