BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
George3
Obsidian | Level 7

Hello all, 

I have a relatively quick question.  After reshaping a SAS dataset from long to wide format, the first line of the new dataset contains unwanted information.  Because I am planning to use some of the information later in another process, things would be easier later if the first line of the new dataset were deleted.  After reading several message boards, I haven't found anything that will get me where I want to go.  The two mock datafiles below show my current position with the data and where I need to be.  In data have, the first line of the data contain N min max mean and std as the first line.  I need what is in the data want where the first line is removed.  This way I can do other things with the data.  When I tried FIRSTOBS, the later process did not accept the numerical values the way it needed to do so, and frankly, it will be cleaner for all purposes.  How do I accomplish this?  It will go a long way to my work.  Thank you. 

 

data have;
input n min max mean std;
datalines;
N min max mean std
2600 9.28 39.12 21.02 5.51
;

 

data want;
input n min max mean std;
datalines;
2600 9.28 39.12 21.02 5.51
;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if _n_=1 then delete;
run;
--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26
data want;
    set have;
    if _n_=1 then delete;
run;
--
Paige Miller
George3
Obsidian | Level 7

Thank you. Worked perfectly. 

Kurt_Bremser
Super User

What's the problem with firstobs? It's THE method for jumping over header lines, as it will avoid the ERROR messages caused by the column names where numeric data is expected.

George3
Obsidian | Level 7

When I got further down the road to using the information in a macro, it gave errors.  I just did it with the, now, accepted solution and it ran without errors.  Thank you. 

Reeza
Super User
Are you reading text files? Or cards or something else? There's many ways to control which lines to read in various ways. For example you can read all text files in a folder/list in SAS without reading each of the headers in a single data step.
George3
Obsidian | Level 7

Hello, 

I am reading the data that is left from using proc transpose.  So, the sas data are reshaped as sas data.  The accepted solution worked for me.  Thank you. 

Kurt_Bremser
Super User

@George3 wrote:

Hello, 

I am reading the data that is left from using proc transpose.  So, the sas data are reshaped as sas data.  The accepted solution worked for me.  Thank you. 


Firstobs= will result in the same dataset. Just run

data test1;
set sashelp.class (firstobs=2);
run;

data test2;
set sashelp.class;
if _n_ = 1 then delete;
run;

and compare the resulting datasets.

George3
Obsidian | Level 7

Will do.  Thank you. 

Tom
Super User Tom
Super User

@George3 wrote:

Hello, 

I am reading the data that is left from using proc transpose.  So, the sas data are reshaped as sas data.  The accepted solution worked for me.  Thank you. 


Note if there is a way to detect that first row using the values of the variables then you can use dataset options to have PROC TRANSPOSE not write the observation to begin with. 

 

For example if the extra row has a missing value for the BY variable.

proc transpose data=have out=want(where=(not missing(group)));
  by group;
  var value ;
  id name;
run;

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2235 views
  • 4 likes
  • 5 in conversation