Professional Documents
Culture Documents
Data one;
drop i j;
array a[60];
array b[60];
do j=1 to 1000;
do i=1 to 60;
a[i]=int(ranuni(i+j)*10);
b[i]=int(ranuni(j)*10);
end;
output;
end;
run;
Data two;
drop i j;
array a[60];
array b[60];
do j=1 to 1000;
do i=1 to 60;
a[i]=int(ranuni(i+j)*10);
b[i]=int(ranuni(j)*10);
end;
output;
end;
run;
WE HAVE TO CREATE A SAS DATA SET "THREE" THAT SHOULD HAVE DIFFERENCE
OF THE COMMON VARIABLES OF DATA SETS "ONE" AND "TWO".
WE HAVE A SAS DATA SET:
ONE
EMP_ID
NAME
SALARY
----------------------------------------------------101
RAM
500
102
SITA
600
103
RADHA
700
104
RAVAN
800
105
ARJUN
900
106
BHIM
1000
WE NEED TO CREATE ANOTHER SAS DATA SET:
EMP_ID
NAME
SALARY
SALARY/TOTAL
----------------------------------------------------------------------------------------------101
RAM
500
500/4700
102
SITA
600
600/4700
103
RADHA
700
700/4700
104
RAVAN
800
800/4700
105
ARJUN
900
900/4700
106
BHIM
1000
1000/4700
We have a SAS data set TEST
data test;
input Cust_ID $ visit $ visdt date7.;
format visdt date7.;
cards;
001 uns 01jun13
001 visit1 02jun13
001 visit2 03jun13
001 uns 04jun13
001 uns 05jun13
001 visit3 06jun13
001 uns 07jun13
001 uns 08jun13
001 uns 01jun13
001 visit4 02jun13
001 visit5 03jun13
001 uns 04jun13
001 uns 05jun13
001 visit6 06jun13
001 uns 07jun13
001 uns 08jun13
;
run;
We want the output like:
Cust_ID Vist
001
001
001
001
001
001
001
001
001
001
001
001
001
001
001
001
uns
visit1
visit2
uns
uns
visit3
uns
uns
uns
visit4
visit5
uns
uns
visit6
uns
uns
visdt
01JUN13
02JUN13
03JUN13
04JUN13
05JUN13
06JUN13
07JUN13
08JUN13
01JUN13
02JUN13
03JUN13
04JUN13
05JUN13
06JUN13
07JUN13
08JUN13
Visitseq
0.1
1.0
2.0
2.1
2.2
3.0
3.1
3.2
3.3
4.0
5.0
5.1
5.2
6.0
6.1
6.2
a1 a2 a3 a4 a5 a6 a7 a8 a9 a10
--------------------------------1 0 0 0 5 6 0 0 0 10
0 2 3 0 0 0 0 0 0 0
0 0 0 4 0 0 7 8 0 0
0 0 0 0 0 0 0 0 9 0
Variables: X A1-A10
I will always appreciate most efficient SAS program which is taking the least resources.
We have a abc.doc file having values:
ram,21,500
sita,22,600
radha,23,700
How to read abc.doc file to make a SAS data set work.abc:
work.abc
--------------Name
Age
Ram
21
Sita
22
Radha 23
Salary
500
600
700
Write a SAS program to create another SAS data set TWO by reading SAS data set ONE:
TWO
Fname
Mname
Lname
Ram
Sita
Radha
Arjun
Kumar
m
Singh
Pathak
Rana
Kumari
Product_ID
222
Required Output:
Obs
visit
_101
_102
_103
1
2
3
v1
v2
v3
1
1
1
1
1
.
.
.
1
Program:
data two;
set one;
drop i;
array a[3] _101 _102 _103;
do i=1 to dim(a);
a[i]=1;
end;
run;
proc transpose data=two out=three (drop=_name_);
by visit;
id pt;
run;
data four;
set three;
by visit;
if first.visit;
run;
proc print;
run;
Can anyone help me in write more efficient program than this as we are solving it by using three
different steps?
Obs
1
2
3
4
5
6
location
australia
United States
India
pak
Sri lanka
NP
population
1500
800
1000
900
500
300
In the above scenario we can see that for the observation pak and NP .$country format is not
applicable.
Write a program to count the number of observations on which $country (user defined format) is
not applied.
Cost
-------700
800
900
TWO
Var2
a
b
c
d
e
f
g
h
Var1
3
5
10
10
7
7
6
9
a
b
g
e
f
h
c
d
Week
1
Attendance
5
Var2
3
5
6
7
7
9
10
10
Var3
0
0
0
1
1
0
1
1
101
101
101
102
102
103
2
3
4
1
2
3
4
6
3
1
3
6
Present days
18
4
6
You have a SAS data set one. In this SAS data set you have a variable number. You have to create
other SAS data set(TWO) and that data set should have one variable having name 'Prime_numbers', it
should contain only prime numbers from variable 'Numbers'.
--------| One |
---------
Two
Numbers
---------------17
21
55
61
88
100
15
31
50
99
89
51
Prime_Numbers
17
61
31
89
51
Formatted Input
Ram 21 500 Friday,January 1,1960
Sita
22 600 Saturday,january 1,1960
Radha 23 700 Sunday,january 1,1960
We have to create a SAS dataset from this raw data set.
output:
Name
Ram
Sita
Radha
Age
21
22
23
Salary
500
600
700
Hire_date
01jan1960
02jan1960
03jan1960
Solution:
data one;
infile 'Filename';
length x $ 10 y $ 10 z $ 10 b $ 15;
input name $ age salary @15 H_D $30.;
keep name age salary Hire_date;
x=scan(H_D,2);
z=scan(H_D,4);
a=strip(x)||strip(z);
b=tranwrd(a,substr(a,1,length(a)-4),substr(a,1,3));
day+1;
k=month(input(b,monyy7.));
Hire_Date=mdy(k,day,z);
format final date9.;
run;
proc print data=one;
run;