- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have been trying to create new variables in a dataset that I exported into SAS studio UE. I have tried this multiple times. Everytime, I try to create new variables it deletes the existing variables, and there are blanks in the columns of the new variables I tried to create. I have been trying to create new variables regarding age at a particular event. I have tried this multiple ways; however, I still end up getting a period( (.) which means blank in SAS) in the one row for each variable. Also, none of the previous dataset information appears in the output after running this step; thus, I tried to add a Keep var statement. Prior to running this step I run the Libname and DATA set statement. I provided screen shots of my last coding attempt.
Can any one assist or give any kind of advice? If so, I would greatly appreciate it!
Thanks,
LMP
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1) I don't see a SET statement in your code on the second data step. So instead of bringing data in from an existing set you are creating a new one with all missing values for the variables in the KEEP statements.. Try:
data mydata.temp; set mydata.bllcinckids2014;
and add you calculations to that data step.
2) Your syntax for YRDIF is incorrect. You likely want age = yrdif(dob, sampledate,'ACT/ACT'); the Earlier date should be referenced first and YRDIF requires the basis argument of ACT/ACT or the 360 365 variants. Your code should have thrown many error messages.
3) ALL variables are kept by default. Drop may be easier to use. Note that you can use variable lists to shorten the code:
Keep Result: ; would keep all of the variables whose names start with Result (note that there is a : at the end)
or
Drop Result: ; would remove all of the result variables.
4) Many times when there are so many variables with indexed names such as Result, Test Sampledate and so on it indicates that the data structure may be incorrect.
5) Post LOG results when you get errors. And copy/paste Code using the forum {i} menu icon. Noone is going to retype code from a picture to test the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
1) I don't see a SET statement in your code on the second data step. So instead of bringing data in from an existing set you are creating a new one with all missing values for the variables in the KEEP statements.. Try:
data mydata.temp; set mydata.bllcinckids2014;
and add you calculations to that data step.
2) Your syntax for YRDIF is incorrect. You likely want age = yrdif(dob, sampledate,'ACT/ACT'); the Earlier date should be referenced first and YRDIF requires the basis argument of ACT/ACT or the 360 365 variants. Your code should have thrown many error messages.
3) ALL variables are kept by default. Drop may be easier to use. Note that you can use variable lists to shorten the code:
Keep Result: ; would keep all of the variables whose names start with Result (note that there is a : at the end)
or
Drop Result: ; would remove all of the result variables.
4) Many times when there are so many variables with indexed names such as Result, Test Sampledate and so on it indicates that the data structure may be incorrect.
5) Post LOG results when you get errors. And copy/paste Code using the forum {i} menu icon. Noone is going to retype code from a picture to test the results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you so much ! It worked!