Help using Base SAS procedures

Leaving a space between two datasets

Reply
Frequent Contributor
Posts: 78

Leaving a space between two datasets

Hi all, I basically have two datasets as described below.

Dataset A
key year make model Bodystyle
24586A 2010 HOL COMMODORE Sedan
12692S 2010 BMW 135 Coupe
25496B 2010 TOY CAMRY Sedan
79632V 2010 VOK GOLF Hatchback
78542C 2010 MAZ 3 Hatchback


Dataset B
make model bodystyle guide_1 guide_2 guide_3 guide_4 guide_5
BMW 135 Coupe 1 2 0 0 6
BMW X5 4WD 0 10 0 5 40
TOY CAMRY Sedan 0 0 3 6 20
TOY RAV4 4WD 80 1 7 8 50

I am indexing Data A to Data B by make model and bodystyle and naming the new dataset as Dataset C.

Basically I want to be able to manipulate how Dataset C will appear in a way that retaining all the results in Data A on the top bit of Dataset C. Then leave two rows blank then present the results that match in Datset B after the blank rows.

I am not sure if this can be done in SAS. But this is an example that I'd been trying to obtain... as below -

key year make model Bodystyle guide_1 guide_2 guide_3 guide_4 guide_5
24586A 2010 HOL COMMODORE Sedan
12692S 2010 BMW 135 Coupe
25496B 2010 TOY CAMRY Sedan
79632V 2010 VOK GOLF Hatchback
78542C 2010 MAZ 3 Hatchback


key Year make model Bodystyle guide_1 guide_2 guide_3 guide_4 guide_5
KBI10B 2009 BMW 135 Coupe 1 2 0 0 6
KCU10B 2008 BMW 136 Coupe 1 3 1 1 9
KCT10B 2007 BMW 137 Coupe 2 2 5 5 10
KDJ10C 2009 TOY CAMRY Sedan 0 0 3 6 20

Hoping someone will be able to help me out on this one. Cheers.
Frequent Contributor
Posts: 95

Re: Leaving a space between two datasets

Can you explain more about what you need?

My suggestion would be to produce a report (rather than a dataset) that first prints Dataset A using one PROC PRINT then prints Dataset C using a second PROC PRINT.


If you really want a SAS Dataset with both, you could start here:

[pre]
data set4;
do until (eof);
set set1 end=eof;
output;
end;
do until (eof2);
set set3 end=eof2;
output;
end;
run;
[/pre]

The spaces can be added with a little more programming.
Respected Advisor
Posts: 3,908

Re: Leaving a space between two datasets

Yennie

A SAS table is not the same like an Excel spreadsheet. Adding empty rows would mean observations with all variables set to missings to the SAS table. This would influence all further calculations.

What you need is one SAS table (dataset) with all the data from table A and table B.

1. Use a datastep or PROC TRANSPOSE to bring dataset A into the structure of dataset B.
2. Create a new dataset C by combining A and B (add a variable identifying where the data comes from).
3. Use something like PROC REPORT to create the desired output (Proc Report allows you to add empty lines between by groups).

HTH
Patrick Message was edited by: Patrick
Ask a Question
Discussion stats
  • 2 replies
  • 246 views
  • 0 likes
  • 3 in conversation