- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data want;
set have;
if _n_=1 then delete;
run;
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you. Worked perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Will do. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;