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

I created a code to read the datalines below,

 

data STD;
input Name : $5. Var1 Var2 Var3;
Mean = Mean(Var1, Var2, Var3);
STD1 = STD (Var1, Var2, Var3);
STD = round(STD1,0.01);
drop STD1;
datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;
run;

 

How can I create another data set that only contains one data step to show only observations that has STD less than or equal to 150?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

None of the observations in the data you've posted appears to satisfy the condition - but here how you can write to two different tables in one go.

data STD std2;
  input Name : $5. Var1 Var2 Var3;
  Mean = Mean(Var1, Var2, Var3);
  STD1 = STD (Var1, Var2, Var3);
  STD = round(STD1,0.01);
  drop STD1;
  output std;
  if std<=150 then output std2;
  datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

None of the observations in the data you've posted appears to satisfy the condition - but here how you can write to two different tables in one go.

data STD std2;
  input Name : $5. Var1 Var2 Var3;
  Mean = Mean(Var1, Var2, Var3);
  STD1 = STD (Var1, Var2, Var3);
  STD = round(STD1,0.01);
  drop STD1;
  output std;
  if std<=150 then output std2;
  datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;
ed_sas_member
Meteorite | Level 14

Hi @skjhzzang 

 

You can also write one statement to calculate the rounded standard deviation .

 

data want want2;
	input Name : $5. Var1 Var2 Var3;
	Mean=Mean(Var1, Var2, Var3);
	STD=round(STD (Var1, Var2, Var3), 0.01);
	if std <160 then output want2;
	output want;
	datalines;
MATT 145 349 48
Susan 194 578 300
Tom 394 84 291
Jayce 394 58 279
;
run;

proc print data=want;
run;
proc print data=want2;
run;

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 769 views
  • 1 like
  • 4 in conversation