data insertvalues;
set sashelp.class;
run;
data newvalues;
set insertvalues ;
output;
if mod(_n_,2)=0 then do ;
name='Anand';
sex='M';
age=16;
Height= 8.11 ; Weight= 54.22;
output;
end;
proc print;
run;
how to insert values conditionally in proc sql
Maxim 14. Use the Right Tool.
Here, it is the data step, which you already use. Forget SQL whenever sequence matters, and using it here would be pure idiocy.
That something can't or shouldn't be done is precious knowledge. And being told so is not convincing for some. I suspect that such is the purpose of this exercise.
@PGStats wrote:
That something can't or shouldn't be done is precious knowledge. And being told so is not convincing for some. I suspect that such is the purpose of this exercise.
True, true.
@PGStats wrote:
That something can't or shouldn't be done is precious knowledge. And being told so is not convincing for some. I suspect that such is the purpose of this exercise.
I also wonder how well the poster is translating or understanding the original assignment.
Juola's metatheroem: You will seldom misunderstand a problem so as to make it simpler.
Dr. Robert Juola was my first professor in statistics and made this comment after several assignments ...
If this is another of your useless homeworks (what imbecile comes up with such stupid exercises for things you will NEVER do in real life, and where the time could have been used for teaching meaningful things like hash objects, instead of being a total waste?), here some hints:
As you will see, the code will be unwieldy and ugly as hell, and just an illustration what being a total idiot entices. Scratch this experience from your memory ASAP, it only wastes precious neurons.
Hi,
there is a way...
PROC SQL ;
CREATE VIEW CLASS AS
SELECT monotonic() AS _N_,*
FROM sashelp.class
;
CREATE VIEW class_hlp AS
SELECT monotonic()+.1 AS _N_,
'Anand' AS name,
'M' AS sex,
16 AS age,
8.11 AS Height,
54.22 AS Weight
FROM CLASS
;
CREATE TABLE want(DROP=_N_) AS
SELECT *
FROM CLASS
UNION CORRESPONDING ALL
SELECT *
FROM class_hlp
WHERE (mod(int(_N_), 2)=0)
ORDER BY _N_
;
DROP VIEW class, class_hlp;
QUIT;
- Cheers -
That's exactly what I do 🤗 and meet the requirement 🎉
I conditionally insert values in a dataset with PROC SQL
- Cheers -
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 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: