So I am trying to edit a table in SAS where the name shows up on the side of the data instead of above. The table looks like:
A | Offered | Answered | IN | OUT |
Christina | ||||
mapping | 1 | 1 | :00:03 | :00:00 |
Bob | ||||
mapping | 2 | 2 | :01:05 | :00:00 |
What I would like it to be is
Name | Type | Offered | Answered | IN | OUT |
Christina | mapping | 1 | 1 | :00:03 | :00:00 |
Bob | mapping | 2 | 2 | :01:05 | :00:00 |
Any advice on how to code this?
Looks like you are trying to read in a REPORT instead of an actual dataset. How did you create the dataset?
Your code is close, but you need to RETAIN the new variable that has the block header so that is stays the same for all of the rows displayed under the block header.
data have;
input A :$20. Offered Answered IN $ OUT $;
cards;
Christina . . . .
mapping 1 1 :00:03 :00:00
Bob . . . .
mapping 2 2 :01:05 :00:00
;
data want;
length name type $20;
set have;
if missing(offered) then do;
name=A;
delete;
end;
type=A ;
drop A;
retain name;
run;
Result:
OBS name type Offered Answered IN OUT 1 Christina mapping 1 1 :00:03 :00:00 2 Bob mapping 2 2 :01:05 :00:00
I did add this code so it broke up the A column. I have not sorted the data to change the order, so the name that is above the call information would go with the data.
data EditCleanup; set cleanup; if A = "mapping" then Type = "Mapping"; if A NE "mapping" then Name = A; run;
Just how was beginning "table" created? That step could very well be the place to address the issue.
If your data does not have other values than "mapping" for Type it is a pretty useless variable.
Or perhaps provide a more comprehensive example of the data, which is best done as data step code so we have something to run code with.
This is a table I have edited down from a much bigger table that includes various types of calls that occur and time. This table is one that is like a PDF turned Excel where there are lots of merged cells and extra blank lines for no reason. I just took a basic task that I am looking to do on a large scale for confidentiality reasons.
Looks like you are trying to read in a REPORT instead of an actual dataset. How did you create the dataset?
Your code is close, but you need to RETAIN the new variable that has the block header so that is stays the same for all of the rows displayed under the block header.
data have;
input A :$20. Offered Answered IN $ OUT $;
cards;
Christina . . . .
mapping 1 1 :00:03 :00:00
Bob . . . .
mapping 2 2 :01:05 :00:00
;
data want;
length name type $20;
set have;
if missing(offered) then do;
name=A;
delete;
end;
type=A ;
drop A;
retain name;
run;
Result:
OBS name type Offered Answered IN OUT 1 Christina mapping 1 1 :00:03 :00:00 2 Bob mapping 2 2 :01:05 :00:00
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.