Hi guys, I want to add this col0 to the top of the dataset "have", i.e header this dataset,
but with using this proc sql code the record will be add to the bottom, any help to put it
as the header of the table rather than the bottom?
proc sql;
*Add new record;
insert into have
set col0='Race'
;
quit;
Thanks,
V
SQL isn't necessarily the right tool to solve every problem. Here's another approach:
data header_record;
if 0 then set have; /* define identical variable attributes */
col0 = 'Race';
output;
stop;
run;
proc append data=have base=header_record;
run;
Good luck.
Why do you want it on the top?
resorting the table can help. If you always want the newest at the top, add a load time column, and sort it by descending.
SQL isn't necessarily the right tool to solve every problem. Here's another approach:
data header_record;
if 0 then set have; /* define identical variable attributes */
col0 = 'Race';
output;
stop;
run;
proc append data=have base=header_record;
run;
Good luck.
I know, for this reason I ask.
A question, which difference show your code with this other one?
data new0;
length col0 $30;
col0='Race';
run;
data newhave;
set new0 have;
run;
Thanks.
V
sorry, this one...to compare with yours:
data header_record;
length col0 $30;
col0='Race';
run;
data have;
set header_record have;
run;
Thanks.
V
They all work (assuming $30 is the right length for col0).
PROC APPEND will run slightly faster than the DATA step version. But that may not be an issue. In fact it has the downside feature of less flexibility in naming the output data set.
Your DATA step variations require prior knowledge of the proper length for COL0. To get around that requirement, I used the more complex DATA step to create HEADER_RECORD. Even if you stick with your most recent approach, I would still recommend using my version of the DATA step that creates HEADER_RECORD. It eliminates the chance that you'll make a mistake when setting a length for COL0. The best reason for using the LENGTH statement approach is if the length for COL0 in HAVE is too short and you wish to set a longer length.
Good luck.
Completelly agree, thank you for the explanation, it is exactly I wanted to understand to avoid a possible truncation issue for not considering the right length for the col0 variable.
Or a SQL alternative approach .
proc sql; create table want as select 'Patrick' as Name length=20 from sashelp.class(obs=1) outer union corresponding select * from sashelp.class; quit;
Ksharp
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!
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.