BookmarkSubscribeRSS Feed
superbibi
Obsidian | Level 7

 I have a dataset as below. I want to keep the value based on the “studyeye”. For example, if it is OD in “studyeye", I keep only the value from “PrevIOP_OD_1". How can I do that in SAS studio?

 


Screen Shot 2016-12-01 at 2.25.23 PM.png
8 REPLIES 8
RahulG
Barite | Level 11

It is insterting problem, what I understand you want to control the column in output dataset based on the value in the table. 

 

In below example, I tried to keep only column Type when Make='Audi'.

 

data cars ;
set sashelp.cars(obs=10);
run;

%macro control_column(cond=,keep_list=);
data cars_new;
set cars;
where &cond;
keep &keep_list;
run;
%mend;

%control_column(cond=Make='Audi', keep_list=Type);
superbibi
Obsidian | Level 7

Thank you Rahul. Do you keep the whole column or just some values in the column? I want to keep only some value of the column. Could you upload part of the dataset?

RahulG
Barite | Level 11

You can execute the above code in SAS studio and see if you are getting desired result.

Reeza
Super User

Based on your data what would you expect as your output?

superbibi
Obsidian | Level 7

I want to have only the PrevIOPOD_1/PrevIOPOS_1 values based on the studyeye.

I come up with a maybe easier solution. I can split the dataset based on the sutdyeye into two subdatasets. Then I can keep one of the PrevIOPOS_1/PrevIOPOS_1. then I combine them again. 

mkeintz
PROC Star

You have shown us the source table.   Now show us explicitly what the result table would look like.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
superbibi
Obsidian | Level 7


Screen Shot 2016-12-05 at 11.19.15 AM.png
David_Luttrell
Obsidian | Level 7

Write a PROC SQL and WHERE using a subquery on the dataset doing a count(*) as count on each scenario, where count >=10

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1239 views
  • 1 like
  • 5 in conversation