BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
GN0001
Barite | Level 11

Hello team,

I have a code like this:

If member in ("A", "B) and code = "T" and payer in ("V") then thisfield = "CCC"

I want to use output statement to bucket it right after the statement is read. I can say:

How can I use output statement? How can I use thisfield along with output statement?

 

Respectfully,

CloudsInSky

Blue Blue
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

One more tip I'll add in addition to the good advice provided so far. You can use DATA step to create multiple output data sets in one step, and use conditional OUTPUT statements to control what goes into each. This example creates one data set (WANT1) with your "CCC" records, and a second data set (WANT2) with all other records.

 

data want1 want2;
set have;
If member in ("A", "B) and code = "T" and payer in ("V") then do;
   thisfield = "CCC";
   output want1;
end;
else output want2;
run;

 

View solution in original post

15 REPLIES 15
PaigeMiller
Diamond | Level 26

I don't really understand the question. Bucketing the data and the OUTPUT statement are relatively independent.

 

I want to use output statement to bucket it right after the statement is read.

 

So what is stopping you?

 

 

--
Paige Miller
GN0001
Barite | Level 11

Hello team member,

 

This is what I want and I got it. 

data test1;
set sashelp.class;
format item $8.;
run;

data test2;
set test1;
if Name = "Alfred" then output = "AA";
If Name = "Alice" then output = "BB";
item = Output;
Run;


This gave me what I needed.
Thanks,
blueblue
Blue Blue
Quentin
PROC Star

You can use the OUTPUT statement anywhere in a DATA step.  So could could do:

 

data want;
  set have;
  If member in ("A", "B) and code = "T" and payer in ("V") then thisfield = "CCC" ;
  output;
run;

But that step would give you the same output data without the OUTPUT statement, because the DATA step has an implied OUTPUT statement. 

 

Perhaps you could show a bit more of what you are trying to do.  You could post code to create a dataset with a few records of example data, and then show the dataset you would like to create from that example data, and the code you have tried.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
WarrenKuhfeld
Rhodochrosite | Level 12
If member in ("A", "B) and code = "T" and payer in ("V") then do;
thisfield = "CCC";
output;
end;

If you are asking to conditionally output only after setting thisfield, you would do it as above. 

ChrisHemedinger
Community Manager

One more tip I'll add in addition to the good advice provided so far. You can use DATA step to create multiple output data sets in one step, and use conditional OUTPUT statements to control what goes into each. This example creates one data set (WANT1) with your "CCC" records, and a second data set (WANT2) with all other records.

 

data want1 want2;
set have;
If member in ("A", "B) and code = "T" and payer in ("V") then do;
   thisfield = "CCC";
   output want1;
end;
else output want2;
run;

 

GN0001
Barite | Level 11

Hello team,

 

I want this output (want1) to be value for a variable such as productName.

 

productName =want1
prouctName = want2
an so on.

 I appreciate your help.

 

Thanks,

Blue Blue

Blue Blue
GN0001
Barite | Level 11

Hello Chris,

data want1 want2;
set have;
If member in ("A", "B) and code = "T" and payer in ("V") then do;
   thisfield = "CCC";
   output want1;
end;
else output want2;
run;

I have more than two if statements. I have 8 if statements. How can I place them in "if and else statements. Instead of data want1, want2, I have want1, want2, want3, want4, want5, want6, want7, want8.

Regards,

blue & blue

Blue Blue
GN0001
Barite | Level 11
Hello,
Thank you so very much for the response. What would be the last statement ? Else if or else?
Respectfully
Blue blue
Blue Blue
Quentin
PROC Star

@GN0001 wrote:
Hello,
Thank you so very much for the response. What would be the last statement ? Else if or else?
Respectfully
Blue blue

It's up to you to decide, as the programmer.  Personally, if I write IF/ELSE IF blocks, I like to explicitly handle all the expected scenarios with ELSE IF statements.  Then I add an ELSE statement which generates an error message if the data have any surprises.  e.g.:

if var='A' then do ;
  *...;
end;
else if var='B' then do ;
  *...;
end;
else if var='C' then do ;  /*else if statements for every expected value*/
  *...;
end;
else do;
  put "ER" "ROR: unexpected value " var= ;
end;

that allows your code to detect any records that fall through gaps in the logic.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
GN0001
Barite | Level 11
I am outpouring observations only not a dataset.
Thanks,
Blu blue
Blue Blue
GN0001
Barite | Level 11

Hello team;

If member in ("A", "B) and code = "T" and payer in ("V") then do;
thisfield = "CCC";
output;
end;

This syntax gives errors:

 

ERROR 117-185: There were 8 unclosed DO blocks.

Thank you for your help.

Blue Blue

Blue Blue

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 15 replies
  • 486 views
  • 8 likes
  • 7 in conversation