楼主: bobguy
2016 2

[学习分享] choosec function [推广有奖]

学科带头人

7%

还不是VIP/贵宾

-

威望
0
论坛币
14187 个
通用积分
28.9279
学术水平
344 点
热心指数
363 点
信用等级
228 点
经验
104882 点
帖子
1846
精华
0
在线时间
1608 小时
注册时间
2008-7-18
最后登录
2019-3-8

中级热心勋章

楼主
bobguy 发表于 2012-12-28 00:06:25 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
Here is an example how to use choosec to create a random sample with values "A","B","C","D","E".


data sample;
   length x $1;
   do i=1 to 100;
      n=ceil(5*ranuni(123));
      x=chooseC(n,"A","B","C","D","E");
      output;
    end;
run;

proc freq data=sample;
table x;
run;

************************;
Syntax CHOOSEC (index-expression, selection-1 <,…selection-n> )

Required Arguments index-expression specifies a numeric constant, variable, or expression.
selection specifies a character constant, variable, or expression. The value of this argument is returned by the CHOOSEC function.

Details Length of Returned VariableIn a DATA step, if the CHOOSEC function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes.


The BasicsThe CHOOSEC function uses the value of index-expression to select from the arguments that follow. For example, if index-expression is three, CHOOSEC returns the value of selection-3. If the first argument is negative, the function counts backwards from the list of arguments, and returns that value.



Comparisons The CHOOSEC function is similar to the CHOOSEN function except that CHOOSEC returns a character value while CHOOSEN returns a numeric value.

Example The following example shows how CHOOSEC chooses from a series of values:
data _null_;   Fruit=choosec(1,'apple','orange','pear','fig');   Color=choosec(3,'red','blue','green','yellow');   Planet=choosec(2,'Mars','Mercury','Uranus');   Sport=choosec(-3,'soccer','baseball','gymnastics','skiing');   put Fruit= Color= Planet= Sport=;run;
SAS writes the following line to the log:
Fruit=apple Color=green Planet=Mercury Sport=baseball







二维码

扫码加我 拉你入群

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

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

关键词:function choose CHOO CHO CTI function example

已有 3 人评分学术水平 热心指数 信用等级 收起 理由
webgu + 1 + 1 + 1 nice
hopewell + 1 + 1 + 1 精彩帖子
ziyenano + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

沙发
henryyhl 发表于 2012-12-28 09:57:08
学习了。请问这个函数有什么实际的应用呢?为了随机抽样?
It's not going to be easy, but it is going to be worth it.

藤椅
Bridgenc 发表于 2012-12-28 11:54:22
good to learn the function

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 02:13