Desktop productivity for business analysts and programmers

is not missing statement

Accepted Solution Solved
Reply
Contributor
Posts: 70
Accepted Solution

is not missing statement

Hi All,  

 

I am writing a DataStep to pull only certain information out of a file that i imported into SAS..

 

The part i am having trouble with is when i am trying to tell SAS that if data exists in the field (its a character field) that i want it to output to the specifed table.  My code is below.  Can anyone tell me the correct syntax for this datastep.

 

data work.site;
set work.agent2;
if agent_name = "18F-site" then siteflag = 1;
if siteflag then do;
if agent_name is not missing then output work.site; 
if agent_name = "Subtotal of 18F-site" then siteflag = 0;
end;
drop siteflag;
run;

Accepted Solutions
Solution
‎08-30-2017 05:08 PM
Super User
Posts: 5,372

Re: is not missing statement

If the site you are looking for is always the first one, then it's easy:

 

data site;

set agent2;

if agent_name='18F-site' then delete;

if agent_name='Subtotal of 18F-site' then stop;

run;

 

If the site you are looking for might be in the middle of the data, it takes a little more programming:

 

data site;

set agent2;

if flag=1 then output;

if agent_name='18F-site' then flag=1;

retain flag;

if agent_name='Subtotal of 18F-site' then stop;

run;

View solution in original post


All Replies
Super User
Posts: 19,194

Re: is not missing statement

If not missing(agent_name) then ...

Super User
Posts: 5,372

Re: is not missing statement

Your intention isn't really clear.  Which observations should go into the new data set?

Contributor
Posts: 70

Re: is not missing statement

So i have a list of agents from a CSV file that is seperated by site names (18F-Site) and then a subtotal.

 

So i am looking for each dataset to output all the agent names and information between the site name and the subtotal.

 

When i used the code above, i just got the line with the 18F-Site in it but not the names in between which is what my goal was.

 

Dean

Super User
Super User
Posts: 7,727

Re: is not missing statement

The reason you only get one line out is that siteflag is missing unless assigned on each row, it is not carried over.  You would need to retain this value if you want to use it as a flag like that:

 

data work.site (drop=siteflag);
  set work.agent2;
retain siteflag; if agent_name = "18F-site" then siteflag = 1; if siteflag and not missing(agent_name) then output; if agent_name = "Subtotal of 18F-site" then siteflag = 0; run;

 

 

 

Super User
Posts: 5,372

Re: is not missing statement

If I understand correctly, this might be close to the mark:

 

data site;

set agent2;

if agent_name in ('18F-site', 'Subtotal of 18F-site') then delete;

run;

 

If I misunderstood the proper observations, there must be a fix that is pretty close to this program.

Contributor
Posts: 70

Re: is not missing statement

That would work... but let me see if i can explain how the data itself is setup. it looks something like this...

 

 

Agent_Name     Field1   Field2   Field3  Field4

18F-Site

John                    100       50        15        10

Jame                    50         40        30       15

Rick                     175       35        25        15

Subtotal 18Fsite   325      125      75         40

 

18F-Site2

Mary                   15          20       30         40

Mike                    20         30        40         50

Subtotal 18FSite2 35       50        70        100

 

18F-Site3

and so on

 

So in essense, i only want the data for 18F-Site and not the others and i don't want to go past the subtotal into the informaiton for my other sites.  I think that may make my intention with this a little clearer and the data step i was using may make a little more sense now.

 

Dean

Solution
‎08-30-2017 05:08 PM
Super User
Posts: 5,372

Re: is not missing statement

If the site you are looking for is always the first one, then it's easy:

 

data site;

set agent2;

if agent_name='18F-site' then delete;

if agent_name='Subtotal of 18F-site' then stop;

run;

 

If the site you are looking for might be in the middle of the data, it takes a little more programming:

 

data site;

set agent2;

if flag=1 then output;

if agent_name='18F-site' then flag=1;

retain flag;

if agent_name='Subtotal of 18F-site' then stop;

run;

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 673 views
  • 0 likes
  • 4 in conversation