(SAS) How to pick up dates with ID-based data?
I'm new to SAS and trying to program a simple code.
Original data:
TableA
ID |Date |Type
1 20111111 A
2 20081014 C
3 20051126 A
...
100 20160421 B
From this original data, I want to pick up dates by Type.
Like following
Result (only picking up A and B)
ID | DateofA | DateofB
1 | 20111111 |
2 | |
3 | 20051126 |
...
100 | | 20160421
Could anyone do this?
Thank you for advance.
sas
add a comment |
I'm new to SAS and trying to program a simple code.
Original data:
TableA
ID |Date |Type
1 20111111 A
2 20081014 C
3 20051126 A
...
100 20160421 B
From this original data, I want to pick up dates by Type.
Like following
Result (only picking up A and B)
ID | DateofA | DateofB
1 | 20111111 |
2 | |
3 | 20051126 |
...
100 | | 20160421
Could anyone do this?
Thank you for advance.
sas
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
1
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41
add a comment |
I'm new to SAS and trying to program a simple code.
Original data:
TableA
ID |Date |Type
1 20111111 A
2 20081014 C
3 20051126 A
...
100 20160421 B
From this original data, I want to pick up dates by Type.
Like following
Result (only picking up A and B)
ID | DateofA | DateofB
1 | 20111111 |
2 | |
3 | 20051126 |
...
100 | | 20160421
Could anyone do this?
Thank you for advance.
sas
I'm new to SAS and trying to program a simple code.
Original data:
TableA
ID |Date |Type
1 20111111 A
2 20081014 C
3 20051126 A
...
100 20160421 B
From this original data, I want to pick up dates by Type.
Like following
Result (only picking up A and B)
ID | DateofA | DateofB
1 | 20111111 |
2 | |
3 | 20051126 |
...
100 | | 20160421
Could anyone do this?
Thank you for advance.
sas
sas
edited Nov 15 '18 at 13:32
Richard
9,21721329
9,21721329
asked Nov 15 '18 at 10:59
user3330881user3330881
11
11
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
1
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41
add a comment |
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
1
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
1
1
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41
add a comment |
1 Answer
1
active
oldest
votes
There is a simple way to achieve this using Proc Transpose. To pick up the dates, you need to sort the dataset by Id. and then transpose the dataset by Id(keeping it fixed). The Id statement is also used to create columns using Type. Following is the approach I used:
data inp;
input Id 3. Date yymmdd8. type $2.;
type=strip(type);
format date date9.;
datalines;
1 20111111 A
2 20081014 C
3 20051126 A
4 20031212 B
5 20041127 C
6 20010904 A
7 20010803 C
8 20000702 B
9 19990601 A
10 19980701 C
;
run;
proc sort data=inp; by Id; run;
proc transpose data=inp
out=outp
NAME=Transposed_Col
prefix=DATEOf;
by Id;
id type;
run;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317948%2fsas-how-to-pick-up-dates-with-id-based-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
There is a simple way to achieve this using Proc Transpose. To pick up the dates, you need to sort the dataset by Id. and then transpose the dataset by Id(keeping it fixed). The Id statement is also used to create columns using Type. Following is the approach I used:
data inp;
input Id 3. Date yymmdd8. type $2.;
type=strip(type);
format date date9.;
datalines;
1 20111111 A
2 20081014 C
3 20051126 A
4 20031212 B
5 20041127 C
6 20010904 A
7 20010803 C
8 20000702 B
9 19990601 A
10 19980701 C
;
run;
proc sort data=inp; by Id; run;
proc transpose data=inp
out=outp
NAME=Transposed_Col
prefix=DATEOf;
by Id;
id type;
run;
add a comment |
There is a simple way to achieve this using Proc Transpose. To pick up the dates, you need to sort the dataset by Id. and then transpose the dataset by Id(keeping it fixed). The Id statement is also used to create columns using Type. Following is the approach I used:
data inp;
input Id 3. Date yymmdd8. type $2.;
type=strip(type);
format date date9.;
datalines;
1 20111111 A
2 20081014 C
3 20051126 A
4 20031212 B
5 20041127 C
6 20010904 A
7 20010803 C
8 20000702 B
9 19990601 A
10 19980701 C
;
run;
proc sort data=inp; by Id; run;
proc transpose data=inp
out=outp
NAME=Transposed_Col
prefix=DATEOf;
by Id;
id type;
run;
add a comment |
There is a simple way to achieve this using Proc Transpose. To pick up the dates, you need to sort the dataset by Id. and then transpose the dataset by Id(keeping it fixed). The Id statement is also used to create columns using Type. Following is the approach I used:
data inp;
input Id 3. Date yymmdd8. type $2.;
type=strip(type);
format date date9.;
datalines;
1 20111111 A
2 20081014 C
3 20051126 A
4 20031212 B
5 20041127 C
6 20010904 A
7 20010803 C
8 20000702 B
9 19990601 A
10 19980701 C
;
run;
proc sort data=inp; by Id; run;
proc transpose data=inp
out=outp
NAME=Transposed_Col
prefix=DATEOf;
by Id;
id type;
run;
There is a simple way to achieve this using Proc Transpose. To pick up the dates, you need to sort the dataset by Id. and then transpose the dataset by Id(keeping it fixed). The Id statement is also used to create columns using Type. Following is the approach I used:
data inp;
input Id 3. Date yymmdd8. type $2.;
type=strip(type);
format date date9.;
datalines;
1 20111111 A
2 20081014 C
3 20051126 A
4 20031212 B
5 20041127 C
6 20010904 A
7 20010803 C
8 20000702 B
9 19990601 A
10 19980701 C
;
run;
proc sort data=inp; by Id; run;
proc transpose data=inp
out=outp
NAME=Transposed_Col
prefix=DATEOf;
by Id;
id type;
run;
answered Nov 15 '18 at 19:46
RhythmRhythm
3556
3556
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317948%2fsas-how-to-pick-up-dates-with-id-based-data%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Transpose long to wide in SAS
– user667489
Nov 15 '18 at 11:30
1
I can guess what's wrong but you need to show the code you used and a few of the data lines exactly is in the file you are reading from.
– data _null_
Nov 15 '18 at 13:31
Its not clear what the logic is here at all. Is it just a flip? Why is the second ID missing the value?
– Reeza
Nov 15 '18 at 16:41