BookmarkSubscribeRSS Feed
75063
Obsidian | Level 7

Hi all,

 

I have a data frame as below - 

data test;
input brand $ Freq Freq1 COUNT;
datalines;
A 2 3 8
B 3 5 4
C 4 6 2
D 5 1 1
E 6 5 8
F 7 7 9
;
run;

 

To insert blanks at multiple locations in the observations i use this code. 

 

data want;
set test;
output;
if _n_=3 or _n_=5;
call missing (of _all_);
output;
run;

proc print data=want;
Run;

 

 

 

Is there a procedure to introduce sub headings in place of the blanks - as shown in the desired output. 

 

Thank you!

 

4 REPLIES 4
75063
Obsidian | Level 7

If i am using this code - 

data want;
set test;
if brand ="C" or brand= "E" then do;
output;
brand = 'Title' ;Freq = .; Freq1=. ; COUNT=.;
output;
end;
else output;
run;

 

Then I am getting the same title 'Title' for both the observations. However, I would like to have two different titles                          ("Title1" and "Title2" ) in the two locations. 

Please suggest. 

 

Thank you!

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

This will give you what you are asking for.  There are better ways to do this, but here is a simple fix:

 

data want;

length brand $25;

set test;

if brand ="C" or brand= "E" then do;

output;

if brand = "C" then do brand = 'This is the first title ' ;Freq = .; Freq1=. ; COUNT=.; end;

else if brand = "E" then do brand = 'This is the second title ';Freq = .; Freq1=. ; COUNT=.; end;

output;

end;

else output;

run;

 

 

75063
Obsidian | Level 7

Thank you for your reply. 

I have used the following to get my desired outcome.  

data test;
input brand $ Freq Freq1 COUNT;
datalines;
A 2 3 8
B 3 5 4
C 4 6 2
D 5 1 1
E 6 5 8
F 7 7 9
;
run;

data want;
if 0 then set test;
if _n_=1 then do;
call missing(of _all_);
output;
end;
set test;
output;
run;

data want2;
set want;
if brand =" " then do;
output;
brand = 'Title1' ;Freq = . ; Freq1=.; COUNT=.;
end;
if brand = "D" then do;
output;
brand = 'Title2' ;Freq = . ; Freq1=.; COUNT=.;
output;
end;
else output;
run;

 

However, I can see that your solution is better. Thank you again.  

Reeza
Super User

I posted the solution in your previous post using PROC REPORT. Please do not post your question multiple times.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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