BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

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

 

 

Capture 1 sas code.PNGCapture 2 sas.PNGCapture 3 SAS code.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

LMP
Obsidian | Level 7 LMP
Obsidian | Level 7
Thank you! I will try this out!
LMP
Obsidian | Level 7 LMP
Obsidian | Level 7

Thank you so much ! It worked! Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 2233 views
  • 0 likes
  • 2 in conversation