SAS Procedures

Help using Base SAS procedures
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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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