BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

 

suppose to have the following: 

 

data DB;
  input class :$20. subclass $20.;
cards;

DiseaseC1  Tot  
   .        variant1
   .        variant2
DiseaseC2  Tot  
   .       variant1
   .       variant12
   .	   variant3
   .	   variant15;
run;

Is there a way to get the following? 

 

data DB1;
  input class :$20. subclass $20.;
cards;

DiseaseC1  Tot  
   .        variant1
   .        variant2

DiseaseC2  Tot  
   .       variant1
   .       variant12
   .	   variant3
   .	   variant15;
run;

In other words I need to add a white/empty row always before Tot (except for the first).

Note that names are purely indicatives except for Tot that is always there. 

 

Thank you in advace

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

First let's fix you example input dataset.

data DB;
  input class :$20. subclass $20.;
cards;
DiseaseC1 Tot  
. variant1
. variant2
DiseaseC2  Tot  
. variant1
. variant12
. variant3
. variant15
;

Having that empty first line of data just makes your data step confusing.  And there is no need for a RUN statement.  The in-line data ends at the first line that contains a semi-colon. Or when using CARDS4 (aka DATALINES4) a line that consists of 4 consecutive semi-colons.

 

I would just use two SET statements to make it easier to create the observation with all missing values.

data want;
  set db;
  if subclass='Tot' and _n_>1 then do;
    call missing(of _all_);
    output;
  end;
  set db;
  output;
run;

Results:

Screenshot 2026-06-25 at 1.10.46 PM.png

View solution in original post

7 REPLIES 7
LinusH
Tourmaline | Level 20
It seems you try to create a report in a SAS dataset/table, which is not optimal.
If you have somewhat structured source data, there are several SAS procedures to create reports, like PRINT and REPORT.
You can even use a data step with PUT statements for high degree of customization.
Please share a sample of your source data and we could suggest a proper tool to use for your report.
Data never sleeps
Tom
Super User Tom
Super User

Do you want to make a DATASET?

Or do you want to make a REPORT?

If a REPORT what type of file do you need?  PDF? HTML? Plain old text?

NewUsrStat
Lapis Lazuli | Level 10
I need a dataset.
PaigeMiller
Diamond | Level 26

Can you explain why a dataset has to have a blank line?

 

It makes perfect sense to have an output from PROC REPORT or PROC PRINT with a blank line. I can't think of a reason why a dataset needs a blank line.

--
Paige Miller
Quentin
Super User

Agree, please @NewUsrStat explain why you would want such a dataset.  It's clearly a report.  Even if you're using this dataset to validate someone else's report, I'm not sure it's a good idea.  It's hard for me to come up with a good reason to create this sort of dataset.

 

If you're truly a New User as your screen name implies, one thing that takes time to learn is that sometimes as a programmer, your boss/statistician/analyst will ask you to do something that makes sense to how they're thinking about the problem, but doesn't make sense to implement that way in SAS.  Part of growing into a senior programmer is learning how to identify those issues, and explain/adjust.  For example,  many analysts want to talk about longitudinal data as if it's in a wide format (one record per patient ID, with score_time1 score_time2 score_time3 etc.  It's fine for them to think that way, and sometimes even write requirements that way.  They don't need to know or worry that you actually store the data in a vertical format (with variables ID, Time, Score).

 

I've never worked in pharma (and don't know if you do).  But sometimes I feel like pharma programmers often feel stuck programming whatever a spec asks for, instead of interpreting the spec, and suggesting changes to the spec.

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
Tom
Super User Tom
Super User

First let's fix you example input dataset.

data DB;
  input class :$20. subclass $20.;
cards;
DiseaseC1 Tot  
. variant1
. variant2
DiseaseC2  Tot  
. variant1
. variant12
. variant3
. variant15
;

Having that empty first line of data just makes your data step confusing.  And there is no need for a RUN statement.  The in-line data ends at the first line that contains a semi-colon. Or when using CARDS4 (aka DATALINES4) a line that consists of 4 consecutive semi-colons.

 

I would just use two SET statements to make it easier to create the observation with all missing values.

data want;
  set db;
  if subclass='Tot' and _n_>1 then do;
    call missing(of _all_);
    output;
  end;
  set db;
  output;
run;

Results:

Screenshot 2026-06-25 at 1.10.46 PM.png

Ksharp
Super User

Just have some fun.

 

data DB;
  input class :$20. subclass $20.;
cards;
DiseaseC1 Tot  
. variant1
. variant2
DiseaseC2  Tot  
. variant1
. variant12
. variant3
. variant15
;


data want;
 merge DB DB(keep=subclass rename=(subclass=_sub) firstobs=2);
 output;
 if _sub='Tot' then do;
  call missing(of _all_);output;
 end;
 drop _sub;
run;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 509 views
  • 5 likes
  • 6 in conversation