Hi
I have a dataset where I need to combine values from every other obs and I have no by group.
Your advice is much obliged.
DATA Have;
input Subject $ 1-16 Status $ 17-30 ;
cards;
some info Success
some other innfo
some info Success
new info
RUN;
DATA Want;
input Subject $ 1-16 Status $ 17-30 NewVar $ 31-50;
cards;
some info Success some other innfo
some info Success new info
RUN;
Thank you
Thank you all for your input.
My preferred solution is
data want;
merge have (keep=Subject Status Date)
have (keep=Subject rename=subject=newvar firstobs=2);
if mod(_n_, 2) = 1;
run;
Im not investigating the retain track..
Thank you
The INPUT statement allows you to move on to the next line of data. For example, either of these would be possible:
input Subject $ 1-16 Status $ 17-30 / NewVar $ 1-20;
input Subject $ 1-16 Status$ 17-30 / NewVar $ 31-50;
The slash indicates that the INPUT statement should move to the next line. You just have to complete the INPUT statement so that SAS knows where to find NewVar on the second line.
Good luck.
Thank you for the suggestion. I will try to work on this.
My problem was unfortunately not very well articulated.
The data Have is a large dataset and the Want is what I was thinking is possible to produce in a datastep using some kind of retain?
I have not done much retain code and struggle with this challenge.
Advice on such a datastep with a retain statement (maybe do loops?) code is also much obliged
Merge the data with itself, renaming the variable and starting from the second observation.
Also, drop every other record, or keep every other record depending on how you look at it.
data want;
merge have
have (keep=subject rename=subject=newvar firstobs=2);
if mod(_n_, 2) = 1;
run;
We might have to go back and re-define the starting point.
Is your large data set already a SAS data set, or is it still text?
If it's a SAS data set, what does it look like?
Is it more important to use RETAIN, vs. finding a simple solution that works?
Hi
I found that the merge with itself works fine with this tuning
data want;
merge have (keep=Subject Status Date)
have (keep=Subject rename=subject=newvar firstobs=2);
if mod(_n_, 2) = 1;
run;
If retain is possible I would love to learn howto..
It is a SAS Dataset and looks like this:
Subject | Status | Date |
Feilkode 6013 | Success | 10Feb2016 18:21:40 |
Result: Created reply #8974223 to ticket #ASV-223434 | ||
Får feilmelding 3141 | Success | 10Feb2016 16:36:06 |
Result: Created reply #1215534 to ticket #ORI-985743 | ||
Feilmelding Lag - Lag borte06.02.2016 | Success | 10Feb2016 14:17:17 |
Result: Created reply #12345665to ticket #YXM-95543553 | ||
Får feilmelding 3141 | Success | 09Feb2016 20:45:20 |
Result: Created reply #459345783to ticket #ORI-31254345 |
The subject starting with Result: should be a new variable in the above line.
Retain where Status is missing is what I have tried.
Thank you for the efforts
If you must use RETAIN, here is a starting point:
data want;
infile rawdata;
if mod(_n_, 1) then input Subject $ 1-16 Status $ 17-30;
else do;
input NewVar $ 1-20;
output;
end;
run;
You will need to add a RETAIN statement to get this to work properly.
Thank you all for your input.
My preferred solution is
data want;
merge have (keep=Subject Status Date)
have (keep=Subject rename=subject=newvar firstobs=2);
if mod(_n_, 2) = 1;
run;
Im not investigating the retain track..
Thank you
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.