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
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;
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?
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
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.
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.
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;
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
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
if /* condition */
then do;
/* action */
end;
else if /* another condition */
then do;
/* another action */
end;
/* and so on */
@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.
This depends on the logic you want to implement in your code, so it's up to you.
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
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.