DATA Step, Macro, Functions and more

idea about conditional statement

Accepted Solution Solved
Reply
Regular Contributor
Posts: 150
Accepted Solution

idea about conditional statement

[ Edited ]

Hi, 

I have this dataset  and this is the result I desire 

 

Task_NameAssigned_Toresultcount
Admin QCtcollins@clinical.comAdmin QC 
Image Previewvpandya@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewvpandya@clinical.comImage Preview 
Photo Image Preview QCtcollins@clinical.comPhoto Image Preview QC 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QCmarnofsky@wcclinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QC  1`
Admin QCmarnofsky@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
irRC RECIST Oncologyrbht@bidmc.harvard.edu  
Post Pre-Derm QCcwalsh@clinical.comPost Pre-Derm QC 
Post Review QC 1araju@clinical.comPost Review QC 1 
Post Review QC 2araju@clinical.comPost Review QC 2 
Pre-Dermatologycwalsh@clinical.comPre-Dermatology 
Radiology Review 1csado@partners.org  
Radiology Review 2vassah@hotmail.com  
irRC RECIST Oncology   


and I want an idea to get the result I want  

If the scan if  scan(assigned_to,2,"@")="clinical.com"  then result=assigned_to; 

I want to create a variable that has the values that associated with the clinical.com  email from the variable assigned_to  

but also I want  to create a variable called count witch count the blanks in the assigned_to variable if the value is in the result variable 


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 23,295

Re: idea about conditional statement

Create your list then first:

 

proc sql noprint;
select distinct quote(task_name) into :task_list separated by ", "
from have
where email like '%@clinical.com';
quit;
%put &task_list;

If the macro variable is  too long you'll need a different approach.

View solution in original post


All Replies
Trusted Advisor
Posts: 1,311

Re: idea about conditional statement

Could you

 

  1. Put the incoming data in the form of a sas data set, and
  2. (really important) show what you want the resulting data set to look like.

 

 

 

Super User
Posts: 13,321

Re: idea about conditional statement

Suggestion would be to cut the example data by maybe half.

Then show the desired result as well, which should be easier with the reduced set.

Reason for showing the desired result is the phrase "has the values that associated with the clinical.com email" is not exactly clear.

Does this mean that you want to do something with the "task_name" variable? Get the user name from such as tcollins from the string tcollins@clinical.com or something else.

 

Since each record could only have 1 "blank" what you actually want to count appears to be something else, possibly a summary after this data set is created.

Regular Contributor
Posts: 150

Re: idea about conditional statement

I just edited my post. 

this is a sample data has only one blank but my real data has more 

Super User
Posts: 23,295

Re: idea about conditional statement

Why not use FIND/INDEX instead of SCAN, since you're searching for a specific string set.

Regular Contributor
Posts: 150

Re: idea about conditional statement

This point it doesn't really matter
Regular Contributor
Posts: 150

Re: idea about conditional statement

edited it
Super User
Posts: 23,295

Re: idea about conditional statement

if find('@clincial.com', assigned_to, 'i')>0 then result=task_name;

 

 

Isn't that all you need?

Regular Contributor
Posts: 150

Re: idea about conditional statement

I don't have a problem with this part
I have a problem with the variable count
I need to create count to count how many blanks are they if the values in the variable result without specifying the values of the variable result each time I run the program
Super User
Posts: 23,295

Re: idea about conditional statement

IF/THEN/DO.

Adding on to my previous answer, change it to conditional so that you can add the count. You only show one value of 1, so not sure why the rest are blank or if you want them incremented or something. If so, use RETAIN. If you cannot get it working at this point, post your code. 

 

if <condition> then do;

<multiple sas statements>;
count=1; end;

Please be much more clear in your initial question. 

 

http://documentation.sas.com/?docsetId=lestmtsref&docsetTarget=n0el0y2a02ab1ln1pks3gbac1en3.htm&docs...

Regular Contributor
Posts: 150

Re: idea about conditional statement

I know if then do
the question is
if then always need to specify a value of the variable to subset
I want to specify the variable that has all those values but without mentioning the values
Super User
Posts: 23,295

Re: idea about conditional statement


@mona4u wrote:
I know if then do
the question is
if then always need to specify a value of the variable to subset
I want to specify the variable that has all those values but without mentioning the values

I have no idea what that means.

Regular Contributor
Posts: 150

Re: idea about conditional statement

I mean usually, we subset this way
if var=a and var1=" " then count
if var in ("a", "b") and var1=" " then count


but the code that I need is
if the value in the var then count without specifying the value of the variable
Super User
Posts: 23,295

Re: idea about conditional statement

Yeah, still not following. Show me 5 lines of data and exactly what you want as output - as two different data sets. 

 


@mona4u wrote:
I mean usually, we subset this way
if var=a and var1=" " then count
if var in ("a", "b") and var1=" " then count


but the code that I need is
if the value in the var then count without specifying the value of the variable

 

Regular Contributor
Posts: 150

Re: idea about conditional statement

 

dataset 

Task_NameAssigned_To
Admin QCtcollins@clinical.com
Image Previewvpandya@clinical.com
Admin QCtcollins@clinical.com
Image Previewtcollins@clinical.com
Admin QCtcollins@clinical.com
Image Previewvpandya@clinical.com
Photo Image Preview QCtcollins@clinical.com
Admin QCaraju@clinical.com
Image Previewarodriguez@clinical.com
Admin QCtcollins@clinical.com
Image Previewtcollins@clinical.com
Admin QCvpandya@clinical.com
Image Previewtcollins@clinical.com
Admin QCaraju@clinical.com
Image Previewarodriguez@clinical.com
Admin QCmarnofsky@wcclinical.com
Image Previewtcollins@clinical.com
Admin QCvpandya@clinical.com
Image Previewtcollins@clinical.com
Admin QCtcollins@clinical.com
Image Previewtcollins@clinical.com
Admin QCvpandya@clinical.com
Image Previewtcollins@clinical.com
Admin QCaraju@clinical.com
Image Previewarodriguez@clinical.com
Admin QC 
Admin QCmarnofsky@clinical.com
Image Previewtcollins@clinical.com
irRC RECIST Oncologyrbht@bidmc.harvard.edu
Post Pre-Derm QCcwalsh@clinical.com
Post Review QC 1araju@clinical.com
Post Review QC 2araju@clinical.com
Pre-Dermatologycwalsh@clinical.com
Radiology Review 1csado@partners.org
Radiology Review 2vassah@hotmail.com
irRC RECIST Oncology 

 

 

result I desire 

Task_NameAssigned_Toresultcount
Admin QCtcollins@clinical.comAdmin QC 
Image Previewvpandya@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewvpandya@clinical.comImage Preview 
Photo Image Preview QCtcollins@clinical.comPhoto Image Preview QC 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QCmarnofsky@wcclinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCtcollins@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCvpandya@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
Admin QCaraju@clinical.comAdmin QC 
Image Previewarodriguez@clinical.comImage Preview 
Admin QC  1`
Admin QCmarnofsky@clinical.comAdmin QC 
Image Previewtcollins@clinical.comImage Preview 
irRC RECIST Oncologyrbht@bidmc.harvard.edu  
Post Pre-Derm QCcwalsh@clinical.comPost Pre-Derm QC 
Post Review QC 1araju@clinical.comPost Review QC 1 
Post Review QC 2araju@clinical.comPost Review QC 2 
Pre-Dermatologycwalsh@clinical.comPre-Dermatology 
Radiology Review 1csado@partners.org  
Radiology Review 2vassah@hotmail.com  
irRC RECIST Oncology   

 

 

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 21 replies
  • 136 views
  • 6 likes
  • 4 in conversation