data birthstones;
drop Space Stone;
retain Month Modern Traditional Mystica Ayurvedic Other1-Other3;
infile 'raw-data-file' end=LastMonth dlm=',';
length Month $ 9 Modern Traditional $ 12 Mystical $ 11 Ayurvedic $ 10 Other1-Other3 $ 15;
input @1 Space $1. @;
if Space ne ' ' then do;
if _n_ ne 1 then output;
input @1 Month $;
Stone=1;
Other2='';
Other3='';
end;
else do;
if Stone = 1 then input Modern $;
else if Stone = 2 then input Traditional;
else if Stone = 3 then input Mystical;
else if Stone = 4 then input Ayurvedic;
else if Stone = 5 then input Other1;
else if Stone = 6 then input Other2;
else if Stone = 7 then input Other3;
Stone+1;
end;
if LastMonth then output;
run;
proc print data=birthstones;
title 'Various Birthstones for Each Month';
run;
我想请教一下retain语句以及‘end=’语句以及if Space ne ' ' then do和 if _n_ ne 1 then output在这个程序中分别表示什么意思,以及各有什么用处?非常感谢!!!
这里是Sample Records;
January
Garnet
Garnet
Emerald
Garnet
Rose Quartz
February
Amethyst
Amethyst
Bloodstone
Amethyst
Onyx
Moonstone
March
Aquamarine
Bloodstone
Jade
Bloodstone
Rock Crystal
这里是最后所得结果
work.birthstones
Various Birthstones for Each Month
Obs Month Modern Traditional Mystical Ayurvedic
1 January Garnet Garnet Emerald Garnet
2 February Amethyst Amethyst Bloodstone Amethyst
3 March Aquamarine Bloodstone Jade Bloodstone
4 April Diamond Diamond Opal Diamond
5 May Emerald Emerald Sapphire Agate
6 June Pearl Alexandrite Moonstone Pearl
7 July Ruby Ruby Ruby Ruby
8 August Peridot Sardonyx Diamond Sapphire
9 September Sapphire Sapphire Agate Moonstone
10 October Opal Tourmaline Jasper Opal
11 November Yellow Topaz Citrine Pearl Topaz
12 December Blue Topaz Zircon Onyx Ruby
Obs Other1 Other2 Other3
1 Rose Quartz
2 Onyx Moonstone
3 Rock Crystal
4 Quartz White Sapphire
5 Chrysoprase Beryl
6 Opal Moonstone
7 Carnelian
8 Jade
9 Lapis Lazuli Diamond Chrsolite
10 Pink Tourmaline Zircon Aquamarine
11 Diamond
12 Turquoise Lapis Lazuli
there's no need of "跪求". you may just download 'SAS on-line tutor for base certification' at the ftp site and read section 'reading various types of raw data' -> 'reading hierarchical files'.