由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - ask for help on one SAS code
相关主题
sas adv问题Proc SQL 能不能直接读 非 SAS format 的数据,txt , csv 等
[合集] 刚过了Advanced SAS问个SAS 数据读入的问题
请教SAS问题:这个code有什么办法简化吗?请教SAS base 123 一题
急了,问道SAS题,(下午考)一个关于sas的弱问题。
SAS 问题请教一个sas base问题不明白,请教
SAS proc format的问题A SAS infile problem
SAS问题How to check LOST CARD in SAS log
请教两个关于SAS的问题SAS infile input 问题
相关话题的讨论汇总
话题: mr话题: pet话题: black话题: owner话题: white
进入Statistics版参与讨论
1 (共1页)
p***7
发帖数: 535
1
It may be simple for powerful everyone here. Please help.
How do you input these data into one datadset with cards?
Pet_owner pet number
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
Thanks so much!
;
p***7
发帖数: 535
2
It should be simple for experienced programmers. The difficulty is the
special symbol in the pet_owner variable and its different length. In infile
command we could use $varying, but when it comes with cards/datalines, it
is clueless.
Please help!
Pet_owner pet number
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
j********t
发帖数: 201
3
you might just read in all data first then process each record afterwards
using character functions or Perl Regular Expressions.

data one;
input title $ Pet_owner $ pet $ number;
length name $20.;
name=compress(title)||' '||compress(pet_owner);
cards;
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data one: if one(or more) space(s) always exist(s) between the title
and the name";
run;
data two;
input title $ Pet_owner $ pet $ number;
length name $20.;
name=compress(title)||' '||compress(pet_owner);
cards;
Mr. Black dog 2
Mr.Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data two: if one space is missing between the title and the name";
run;
data three(keep=Pet_owner pet number);
infile cards truncover;
input lines $200.;
length name title Pet_owner pet $20. number 8.;
Pet_owner=scan(lines,1,'.')||'. '||compress(scan(scan(lines,2,'.'),1,' '));
Pet=compress(scan(scan(lines,2,'.'),2,' '));
number=compress(scan(scan(lines,2,'.'),3,' '))*1;
cards;
Mr. Black dog 2
Mr.Black bird 1
Mrs. Green fish 5
Mr. White cat 3
;
run;
proc print;
title "data three: read in all data first.";
title "data three: then use SCAN. to process data";
run;
proc contents;
run;
S*******1
发帖数: 251
4
data one;
input pet_owner $1-12 pet $ number;
cards;
Mr. Black dog 2
Mr. Black bird 1
Mrs. Green fish 5
Mr. White cat 3
run;
proc print data=one;
run;
The SAS System
Obs pet_owner pet number
1 Mr. Black dog 2
2 Mr. Black bird 1
3 Mrs. Green fish 5
4 Mr. White cat 3

【在 p***7 的大作中提到】
: It may be simple for powerful everyone here. Please help.
: How do you input these data into one datadset with cards?
: Pet_owner pet number
: Mr. Black dog 2
: Mr. Black bird 1
: Mrs. Green fish 5
: Mr. White cat 3
: Thanks so much!
: ;

j******o
发帖数: 127
5
You may need read names into two separated variables (combine later), or try
"Pet_owner & $20." in input statement. Good luck.

【在 p***7 的大作中提到】
: It may be simple for powerful everyone here. Please help.
: How do you input these data into one datadset with cards?
: Pet_owner pet number
: Mr. Black dog 2
: Mr. Black bird 1
: Mrs. Green fish 5
: Mr. White cat 3
: Thanks so much!
: ;

p***7
发帖数: 535
6
Thanks everyone and Johnuseas, it helps a lot
t*****w
发帖数: 254
7
use the simpler one;
input pet_owner$ & pet $ number;
1 (共1页)
进入Statistics版参与讨论
相关主题
SAS infile input 问题SAS 问题请教
SAS软件下载地址已失效(as of 3/23/2010)SAS proc format的问题
问几道SAS base 123的题SAS问题
[合集] SAS data input help请教两个关于SAS的问题
sas adv问题Proc SQL 能不能直接读 非 SAS format 的数据,txt , csv 等
[合集] 刚过了Advanced SAS问个SAS 数据读入的问题
请教SAS问题:这个code有什么办法简化吗?请教SAS base 123 一题
急了,问道SAS题,(下午考)一个关于sas的弱问题。
相关话题的讨论汇总
话题: mr话题: pet话题: black话题: owner话题: white