如何做"其中x在......" SAS数据步骤中的语句

时间:2016-02-25 01:09:30

标签: sql sas proc

我有一个大型SAS数据表,其中包含一系列针对我的整个基本客户群的指标(Master_v01)。我有一个单独的数据表,其中包含我想从分析中排除的客户列表(Excluded_Cust)。

是否可以做这样的事情:

data Master_v02;
set Master_v01;
where cust not in (select cust from Excluded_Cust);
run;

这可能吗?

如果没有,那么实现我想要的目标的最佳方法是什么,将我想要排除的客户的基本表从数据中删除?

3 个答案:

答案 0 :(得分:1)

以下是使用带有where子句的宏变量的另一种方法:

<?php require('includes/config.php'); 

//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: index.php'); } 
?>
<html>
    <head>
        <title>*****</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <!--[if lte IE 8]><script src="siteassets/assets/js/ie/hsiv.js"></script><![endif]-->
        <link rel="stylesheet" href="siteassets/assets/css/main.css" />
        <!--[if lte IE 8]><link rel="stylesheet" href="siteassets/assets/css/ie8.css" /><![endif]-->
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('#next').keyup(calculate);
    $('#nextprice').keyup(calculate);
    $('#current').keyup(calculate);
    $('#currentprice').keyup(calculate);
});
function calculate(e)
{
    $('#total').val($('#next').val() * $('#nextprice').val() + $('#current').val() * $('#currentprice').val());
}
</script>

    </head>
    <body class="landing">
        <div id="page-wrapper">

            <!-- Header -->
                <header id="header" class="alt">

                    <nav id="nav">
                        <ul>
                            <li>
                                <a href="#" class="icon fa-angle-down">Menu</a>
                                <ul>
                                    <li><a href="home.php">Current Project</a></li>
                                    <li><a href="next.php">Next Projects</a></li>
                                    <li><a href="prev.php">Previous Projects</a></li>
                                    <li><a href="who.php">Who are we?</a></li>
                                </ul>
                            </li>
                            <li><a href="tickets.php" class="button">Tickets</a></li>
                            <li><a href='logout.php'>Logout</a></li>
                        </ul>
                    </nav>
                </header>

            <!-- Banner -->
                <section id="banner">
                    <h2>********</h2>
                    <p>*******</p>
                    <ul class="actions">
                        <li><a href="home.php" class="button">Current Project</a></li>
                        <li><a href="newproj.php" class="button">Next Projects</a></li>
                        <li><a href="prev.php" class="button">Previous Projects</a></li>
                        <li><a href="who.php" class="button">Who are we?</a></li>
                        <li><a href="tickets.php" class="button special">Tickets</a></li>
                    </ul>
                </section>

            <!-- Main -->




                <section id="main" class="container 75%">
                    <div class="box">
<? 
if($_SERVER['REQUEST_METHOD']=="POST")
{ 
if(strlen($_POST['name2']) == 0)
    { $error_msg ="- Please, provide us with your name.<br>"; } 

if(!empty($error_msg))
    { 
    //Field error 
    echo "<b>Your message can't be send due to the following reason:</b><br><br>"; 
    echo $error_msg; 
    echo "<br>Click on <a href='javascript:history.back(1)'>Go back</a> and provide us with your name.<br><br>"; 
    }
else 
    { 
    $recipient = "*********";  
    $subject = "******";  
    $header = "From: " . $_POST['uwemail'] . "\n"; 
    $mail_body = "Contact script werd op " . date("d-m-Y") . " om " . date("H:i") . " uur uitgevoerd.\n"; 
    $mail_body .= "De volgende persoon zou graag kaarten bestellen:\n\n"; 
    $mail_body .= "Naam: " . $_POST['name2'] . "\n"; 
    $mail_body .= "Met als kaartnummer: " . $_POST['card2'] . "\n"; 
    $mail_body .= "Aantal kaarten voor de lopende productie: " . $_POST['current2'] . "\n"; 
    $mail_body .= "Aantal kaarten voor de komende productie: " . $_POST['next2'] . "\n"; 
    $mail_body .= "Voor een totaal: " . $_POST['total2'] . "\n";            
    $mail_body .= "\n\n -- Einde van het contact bericht --"; 
    mail($recipient, $subject, $mail_body, $header); 
    print "<b>IMPORTANT!</b>";
    print "<br><br>Thank you for your reservation.";
    print "<br><br>Please note that this will be final upon receipt of payment of the total amount of";
    print " POST TOTAAL";
    print "EUR to Mazzini Theatre Productions";
    print "<br><br>Confirmation of reservation and payment instruction details will be sent to you via email.";
    print "<br><br>We are looking forward to meet you.";
    }
} 
else 
{ 
?>      
            <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" name="contact">
                            <div class="row uniform 50%">
                                <div class="6u 12u(mobilep)">
                                Your personal card number
                                    <input type="text" name="card2" id="card" value="<?php echo $_SESSION['username']; ?>" placeholder="Card Number" disabled/>
                                </div>
                                <div class="6u 12u(mobilep)">
                                Please enter your name. (mandatory)
                                    <input type="text" name="name2" id="name" value="" placeholder="Your name" />
                                </div>
                            </div>
                            <div class="row uniform 50%">
                                <div class="6u 12u(mobilep)">
                                Current Project - Smile
                                    <input type="text" name="current2" id="current" value="" placeholder="How many tickets would you like?" />
                                </div>
                                <div class="6u 12u(mobilep)">
                                Next Project - Sand
                                    <input type="text" name="next2" id="next" value="" placeholder="How many tickets would you like?" />
                                </div>
                            </div>
                            <div class="row uniform 50%">
                                <div class="6u 12u(mobilep)">
                                    <input type="hidden" id="currentprice" value="10" />
                                </div>
                                <div class="6u 12u(mobilep)">
                                    <input type="hidden" id="nextprice" value="10" placeholder="" />
                                </div>
                            </div>
                                            <div class="6u 12u(mobile)">
                                                <input name="uwemail" placeholder="Email" type="hidden" value="**THIS WORKS**"/>
                                            </div>
                            <div class="6u 12u(mobilep)">
                            Total price.(In EUR)
                                    <input type="text" name="total2" id="total" value=""  disabled/>
                                </div>
                            </div>

                            <div class="row uniform">
                                <div class="12u">
                                    <ul class="actions align-center">
                                        <li><input type="submit" name="submit"value="Place Order"/></li>
                                    </ul>
                                </div>
                            </div>
                        </form>


<?php 
} 
?> 

                    </div>
                </section>


            <!-- Footer -->
                <footer id="footer">

                    <ul class="copyright">
                        <li>© **DISCLAIMER**</li>
                    </ul>
                </footer>

        </div>

        <!-- Scripts -->
            <script src="siteassets/assets/js/jquery.min.js"></script>
            <script src="siteassets/assets/js/jquery.dropotron.min.js"></script>
            <script src="siteassets/assets/js/jquery.scrollgress.min.js"></script>
            <script src="siteassets/assets/js/skel.min.js"></script>
            <script src="siteassets/assets/js/util.js"></script>
            <!--[if lte IE 8]><script src="siteassets/assets/js/ie/respond.min.js"></script><![endif]-->
            <script src="siteassets/assets/js/main.js"></script>




    </body>
</html>

答案 1 :(得分:0)

我的数据步骤代码有点生疏,但您可以通过查找值并检查匹配来执行此操作。我认为这就是:

data Master_v02;
    set Master_v01;
    set Excluded_Cust key=cust;
    if _iorc_ = 0 then delete;
run;

当然,建议cust中的Excluded_Cust索引。

答案 2 :(得分:0)

我能想到的两种方法:

1.PROC SQL

proc sql;
  create table Master_v02 as
    select * 
      from Master_v01
      where cust not in (select cust from Excluded_cust);
quit;

2.DATA STEP MERGE

首先按cust排序Master_V01和Excluded_cust数据集,然后:

data Master_V02;
  merge Master_V01 (in=Mast)
        Excluded_cust (in=Excl);
  by cust;
  if Mast and not Excl;
run;