楼主: liujx80
5032 19

[SAS] 真正SAS编程高手请指教 [推广有奖]

  • 0关注
  • 0粉丝

高中生

60%

还不是VIP/贵宾

-

威望
0 级
论坛币
34 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
730 点
帖子
47
精华
0
在线时间
4 小时
注册时间
2007-9-4
最后登录
2017-6-3

楼主
liujx80 发表于 2007-9-5 01:27:00 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
In USA, one teacher must have some certificates to be assigned to teach a subject.  One certificate could be used in several assignments, for example, teaching math needs either cert1 or cert2 or cert3. <br><pre>There are two datasets, ‘certificate’ which shows how many certificates one 'id' has, at most 30 certs.<br>the ‘assignment’shows what type of certificates one assignment needs. If one assignment have more than 2 qualified_cert,<br>which means either of them could be counted.<br><br>data certificate;<br>        input id (certArea1-certArea30) ($) ;<br>        datalines;<br>1 32 11 .  . . . . . . . . . . . . . . . . . . . . . . . . . . .  <br>2 32 .  23 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <br>3 23 21 32 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <br>4 30 24 25 . . . . . . . . . . . . . . . . . . . . . . . . . . . <br>                ;<br>        run;<br>data assignment;<br>    input assign $ (qualified_cert1- qualified_cert13) ($)  ;<br>        datalines;<br>a 11 . . . . . . . . . . . .    <br>b 30 11 . . . . . . . . . . .   <br>c 23 . . . . . . . . . . . . <br>d 32 23 . . . . . . . . . . . <br>                        ;<br>run;<br><br>My question is, how to calculate how many people have the required certificate for<br>each assignment. If one person can be qualified for two jobs, then count ‘1/2’for each<br>assignment.<br><br>Basically, I have to first output each value of cert1-cert30 for each observation,<br>then use that value to check if this certificate meets the requirement of<br>assignment(go through the assignment dataset). To avoid count one person with<br>multiple certificates as multiple person, we have to go through the assignment<br>dataset with all his/her certificates for one teacher to get the total number of his<br>match, then we go through the assignment dataset again.<br><br>Would any body tell me how to write this code?<br><br><br></pre>
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:SAS编程 编程高手 请指教 certificates Certificate 高手 SAS 指教

回帖推荐

kofsphere 发表于5楼  查看完整内容

希望是你要求的结果。 这里必须要说明一下,因为没有看你的sample,所以做这个假设- - - 科目种类,即23,32这样的,代表math或者eng的代码种类的数量是有限的!(或者说,即使数量很大,也有办法替换)- - - 虽然我也相信不会出现几百种科目-_-||| 那么: 首先,替换你的raw data values,比如23 32这类的,既然他们没有算术上的意义,那么一律替换为除1以外的素数,举个例子,如果整个dataset中出现过的科目种类是11,21,23, ...

本帖被以下文库推荐

沙发
liujx80 发表于 2007-9-5 01:32:00
any one trying to help must keep one fact in mind that 'certificate' dataset is a over 500,000 records dataset. So optimization must be considered.<br>I tried one code with a lot of MACRO which took me 6-hour CPU time. So I don't think my code is usable and that's why I'm asking help for master of SAS.<br>

藤椅
kofsphere 发表于 2007-9-5 03:44:00
<P><STRONG>对于你的dataset有点疑惑,eg:</STRONG></P>
<P>data certificate;<BR>        input id (certArea1-certArea30) ($) ;<BR>        datalines;<BR>1 32 11 .  . . . . . . . . . . . . . . . . . . . . . . . . . . .  <BR>2 32 .  23 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <BR>3 23 21 32 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <BR>4 30 24 25 . . . . . . . . . . . . . . . . . . . . . . . . . . .</P>
<P><STRONG>如上,比如certArea1,为何它对应的cert的种类会不同?即,certarea1 在第二个第三个obs里面分别是32,23 -是说</STRONG></P>
<P><STRONG>第二三个人在certarea1里面分别取得了32和23分数么?(但你用的又是char)</STRONG> </P>

板凳
liujx80 发表于 2007-9-5 04:11:00
thanks for reading my question.<br><br>The following explanation might be helpful. You can assume certArea1 is the first Certificate he/she obtained. and CertArea30 is the last one. <br>So id ='1' obtained his certificate which is '32' ,for example ,32='math', id='3' obtained his certificate which is '23', for example 23='english'. <br><br>Let's put it in another way, the value of certArea1-certArea30 specify the area of certificate. <br><br>Please let me know if I haven't put it clear.<br>

报纸
kofsphere 发表于 2007-9-5 09:49:00
<P>希望是你要求的结果。</P>
<P>这里必须要说明一下,因为没有看你的sample,所以做这个<STRONG>假设</STRONG>- - - 科目种类,即23,32这样的,代表math或者eng的代码种类的数量是有限的!(或者说,即使数量很大,也有办法替换)- - - 虽然我也相信不会出现几百种科目-_-|||</P>
<P>那么:</P>
<P>首先,替换你的raw data values,比如23 32这类的,既然他们没有算术上的意义,那么一律替换为除1以外的素数,举个例子,如果整个<br>dataset中出现过的科目种类是11,21,23,32,那么,就把它们全部<STRONG><FONT color=#ff0000>对应</FONT></STRONG>替换为3,5,7,11,如果科目种类更多,那么就以此替换下去,换成质数。同时,把certarea1-certarea30里面所有的missing values替换为 <FONT color=#ff0000><STRONG>1</STRONG></FONT>.这个在data step中即使是50w obs相信也可以很快完成。</P>
<P>然后,在新的dataset中增加一个variable,比如叫做prod,作为certarea1-certarea30的乘积。</P>
<P>这样一来,<STRONG><FONT color=#d52b2b>只要各个assignment中的值能够被prod整除,就说明改obs 可以做这个assignment</FONT></STRONG>,<U>从而避免了你文中提到的用2个表的数据做cross comparison,也不存在人数重复计算的问题。</U></P>
<P>但是由于没有你的dataset sample,所以我不把整个code写完,下面是部分草稿,仅为了阐述我上面说的。</P>
<P>data certificate ;      <br>input id (certArea1-certArea30) ($) ;   <br>datalines ;<br>1 11 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . <br>2 11 . 5 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <br>3 5 13 11 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <br>4 7 17 19 . . . . . . . . . . . . . . . . . . . . . . . . . . .<br>;<br>run ;<br>data assignment ;      <br>input assign $ (certArea1-certArea30) ($) ;   <br>datalines ;<br>a 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br>b 7 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br>c 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br>d 11 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . .<br>;<br>run ; <STRONG>*这里我直接替换了数据 ;</STRONG><br>data certificate1 ;<br>set certificate ;<br>array certa[30] certarea1 - certarea30 ;<br>array certa_n[30] certarea_n1 - certarea_n30 ;<br>do i= 1 to 30 ;<br>  certa_n= input( certa, $8.) ; <br>end ;<br>drop i certarea1 - certarea30 ;<br>run ;</P>
<P><STRONG>* 把char换成numeric ;</STRONG></P>
<P>data certificate2 ;<br>set certificate1 ;<br>array certa_n[30] certarea_n1 - certarea_n30 ;<br>do i= 1 to 30 ;<br>  if certa_n=. then certa_n= 1 ;<br>end ;<br>prod = 1 ;<br>do j =1 to 30 ;<br>  <br>  prod =prod*certa_n[j] ;<br>end ;<br>keep id prod ;<br>run ; <STRONG>*加了一个var叫做prod ;</STRONG><br>data certificate3 ;<br>set certificate2 ;<br>if mod(prod,7)=0 or mod(prod,3)=0 then qualified= 1 ;<br>else qualified = 0 ;<br>run ;</P>
<P><STRONG>* 如果可以整除,那么qualified写为1 ,(这里我简略了下,就直接用assign a来测试了下。)<br></STRONG></P><br><br>

[此贴子已经被作者于2007-9-5 9:59:20编辑过]

已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 10 精彩帖子

总评分: 经验 + 3  论坛币 + 10   查看全部评分

地板
liujx80 发表于 2007-9-5 11:12:00
I can see you really have strong math foundation. But I'm not sure if your result is correct.<br><br>Let's put it simpler. Let's suppose we only have four persons 'id=1,2,3,4. Each person has up to 3 certificates .<br>there are only four assignments and each assignment has up to 2 qualified certificates.<br><br>data certificate;<br>        input id (certArea1-certArea3) ($) ;<br>        datalines;<br>1 32 11 .  <br>2 32 .  23 <br>3 23 21 32 <br>4 30 24 25 <br>          ;<br>        run;<br>data assignment;<br>    input assign $ (qualified_cert1- qualified_cert2) ($)  ;<br>        datalines;<br>a 11 .    <br>b 30 11 <br>c 23 . <br>d 32 23 <br>             ;<br>run;<br><br>Let's do it one by one;<br>for 'id=1', he has two certs '32','11', and can meet the requirement of three assignments 'a' , 'b','d'. Thus any assignment<br>counting 'id=1' will be 1/3.  now :<br> a: 1/3<br> b: 1/3<br> c: 0<br> d: 1/3<br><br>for 'id=2', he has two certs '32' '23', and can meet the requirement of two assignments 'c' 'd', but three qualified certs, <br>c:23, d:32 , d:23. thus any assignment counting 'id=2' will be 1/3. now:<br> a: 1/3<br> b: 1/3<br> c: 1/3<br> d: 1/3+1/3+1/3= 1<br><br>after 'id=3', the assignment will be :<br>   a:1/3<br>   b: 1/3<br>   c: 1/3+1/3= 2/3<br>   d: 1+1/3+1/3=1.67<br><br>after 'id=4', the assignment will be:<br> a:1/3<br> b: 1/3+1= 1.3<br> c: 2/3<br> d: 1.67<br><br>So is your result the same? <br><br><br>

7楼
kofsphere 发表于 2007-9-5 19:30:00
<P>上面说的只在于回答‘My question is, how to calculate how many people have the required certificate for<br>each assignment.’</P>
<P><STRONG>如果你要求 If one person can be qualified for two jobs, then count ‘1/2’for each<br>assignment.这个稍作修改也容易,</STRONG></P>
<P><STRONG><U><FONT color=#ff0000>此外,刚刚发现,你误解了我的意思,我并没有把每个obs放到4个assign里面去比较!!而是<br>反过来把各个assign去和每个obs比较整除,并赋上对应的值0 or 1</FONT></U></STRONG></P>
<P>首先,是上面的codes得出的结构表:<br>1 11 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33<br>2 11 . 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 <br>3 5 13 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 <br>4 7 17 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . 2261<br>这里最后一列是前面非missing  value的乘积,<br>那么,在比较这个表中最后一列是否能被assignment表中各个assign对应值整除后,<br>可以得到追加的一列qualified,1代表可以做,2代表不可以,如下</P>
<P>1 11 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1<br>2 11 . 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 0<br>3 5 13 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . 715 0 <br>4 7 17 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . 2261 0 (具体参照我修改的那个assignment表,obs a)</P>
<P>那么现在,如果你要求的不是‘<STRONG>人次’</STRONG>而是<STRONG>具体平均后的’人数‘,</STRONG>那么只需要加入几列,如下</P>
<P>obs                                                                     <STRONG>a  b  c</STRONG>  d            sum _a   _b   _c    _d<br>1 11 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33    <STRONG><FONT color=#ff0000>1  1  0  1          3  1/3  1/3  0     1/3<br></FONT></STRONG>2 11 . 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . 55    <STRONG>0  0  1  1          2  0     0    1/2   1/2<br></STRONG>3 5 13 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . 715  <STRONG>1  0  1  1       3  1/3  0    1/3   1/3<br></STRONG>4 7 17 19 . . . . . . . . . . . . . . . . . . . . . . . . . . . 2261 <STRONG>0  1  0  0      1  0     1    0      0<br></STRONG><br>在这个数据结构中,比如说上面的红字,a b c 对应的数各自代表obs1 可以教授的科目,因为obs1可以同时教授a和b,d 那么他对a,b d<br>3门科目的贡献值就是各1/3,即_a 和_b  _d在obs1时为1/3, 最后对_a _b _c _d 这样的列求和,即是最后的结果,(如果到此我对你的问题没有其他误解的话)</P>
<P>btw,如果这个问题中,科目真的有成百上千个,那么也只需要加一段code,使得这些科目能够<STRONG>对应的</STRONG>和质数进行替换</P>
<P><STRONG>具体code你写起来应该很容易,恕我偷个懒了</STRONG></P>
<P><br><br></P>

[此贴子已经被作者于2007-9-5 19:51:44编辑过]

8楼
liujx80 发表于 2007-9-5 21:23:00
I can see your way is of  greate ingenuity. Howevery, I cannot see what's happening .<br>I think we all appreicate that if you could spend some time writing the code. <br>all you need to do is use the following dataset:<br>data certificate;<br>        input id (certArea1-certArea3) ($) ;<br>        datalines;<br>1 32 11 .  <br>2 32 .  23 <br>3 23 21 32 <br>4 30 24 25 <br>          ;<br>        run;<br>data assignment;<br>    input assign $ (qualified_cert1- qualified_cert2) ($)  ;<br>        datalines;<br>a 11 .    <br>b 30 11 <br>c 23 . <br>d 32 23 <br>             ;<br>run;<br><br>and give me a final dataset with the following result:<br> a: 0.33<br> b: 1.33<br> c: 0.67<br> d: 1.67<br><br><br>

9楼
kofsphere 发表于 2007-9-5 22:40:00
<P><STRONG>既然你要求重复情况也多次计算,我改了下_a - _d的计数,所有代码如下:</STRONG></P>

<P>data certificate ;      <BR>input id (certArea1-certArea30) ($) ;   <BR>datalines ;<BR>1 32 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . <BR>2 32 .  23 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <BR>3 23 21 32 . . . . . . . . . . . . . . . . . . . . . . . . . . .  <BR>4 30 24 25 . . . . . . . . . . . . . . . . . . . . . . . . . . .<BR>;<BR>run ;<BR>data assignment ;      <BR>input assign $ (certArea1-certArea30) ($) ;   <BR>datalines ;<BR>a 11 .  . . . . . . . . . . . . . . . . . . . . . . . . . . . .<BR>b 30 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . .<BR>c 23 .  . . . . . . . . . . . . . . . . . . . . . . . . . . . .<BR>d 32 23 . . . . . . . . . . . . . . . . . . . . . . . . . . . .<BR>;<BR>run ; <BR>data certificate ;<BR> set certificate ;<BR> array cert[30] certarea1-certarea30 ;<BR> do i= 1 to 30 ;<BR>  if cert= 11 then cert= 3 ;<BR>  if cert= 21 then cert= 5 ;<BR>  if cert= 23 then cert= 7 ;<BR>  if cert= 24 then cert= 11 ;<BR>  if cert= 25 then cert= 13 ;<BR>  if cert= 30 then cert= 17 ;<BR>  if cert= 32 then cert= 19 ;<BR> end ;<BR>run ; <STRONG>* replace raw values with prime numbers ;<BR></STRONG>data assignment ;<BR> set assignment ;<BR> array cert[30] certarea1-certarea30 ;<BR> do i= 1 to 30 ;<BR>  if cert= 11 then cert= 3 ;<BR>  if cert= 21 then cert= 5 ;<BR>  if cert= 23 then cert= 7 ;<BR>  if cert= 24 then cert= 11 ;<BR>  if cert= 25 then cert= 13 ;<BR>  if cert= 30 then cert= 17 ;<BR>  if cert= 32 then cert= 19 ;<BR> end ;<BR>run ; <STRONG>* replace raw values with prime numbers ;</STRONG></P>
<P>data certificate1 ;<BR> set certificate ;<BR> array certa[30] certarea1 - certarea30 ;<BR> array certa_n[30] certarea_n1 - certarea_n30 ;<BR> do i= 1 to 30 ;<BR>   certa_n= input( certa, $8.) ; <BR> end ;<BR> drop i certarea1 - certarea30 ;<BR>run ;* transfer to numeric values ;</P>
<P>data certificate2 ;<BR> set certificate1 ;<BR> array certa_n[30] certarea_n1 - certarea_n30 ;<BR> do i= 1 to 30 ;<BR>   if certa_n=. then certa_n= 1 ;<BR> end ;<BR> prod = 1 ;<BR> do j =1 to 30 ;<BR>   prod =prod*certa_n[j] ;<BR> end ;<BR> keep id prod ;<BR>run ; <STRONG>* substitude missing values, and create the product value for each id</STRONG>;</P>
<P><BR>data certificate3 ;<BR> set certificate2 ;</P>
<P> if  mod(prod,3)=0 then qualifieda= 1 ;<BR> else qualifieda = 0 ;</P>
<P> if mod(prod,17)=0 and mod(prod,3) ne 0 then qualifiedb= 1 ;<BR> else if  mod(prod,17)ne 0 and mod(prod,3) =0 then qualifiedb= 1 ;<BR> else if mod(prod,17)=0 and mod(prod,3) =0 then qualifiedb= 2 ;<BR> else qualifiedb = 0 ;</P>
<P> if mod(prod,7)=0  then qualifiedc= 1 ;<BR> else qualifiedc = 0 ;</P>
<P> if mod(prod,19)=0 and mod(prod,7) ne 0 then qualifiedd= 1 ;<BR> else if  mod(prod,19)ne 0 and mod(prod,7) =0 then qualifiedd= 1 ;<BR> else if mod(prod,19)=0 and mod(prod,7) =0 then qualifiedd= 2 ;<BR> else qualifiedd = 0 ;</P>
<P> sum= qualifieda+qualifiedb+qualifiedc+qualifiedd ;<BR> _a= qualifieda/sum ;<BR> _b=qualifiedb/sum ;<BR> _c=qualifiedc/sum ;<BR> _d= qualifiedd/sum ;<BR>run ; <STRONG>* determine the contribution values based on the mod function ;<BR></STRONG>proc means noprint ;<BR> output out= final<BR>  sum= ;<BR> var _a _b _c _d ;</P>
<P>run ;<BR></P>

10楼
kofsphere 发表于 2007-9-5 22:41:00
<A><br>
<H1>The SAS System<br>_TYPE_ _FREQ_ _a _b _c _d <br>0 4 0.33333 1.33333 0.66667 1.66667 </H1></A>

[此贴子已经被作者于2007-9-5 22:45:07编辑过]

您需要登录后才可以回帖 登录 | 我要注册

客服
GMT+8, 2026-12-4 17:38