Hello,
So I have an array like this:
data tempo;
input employee_id:6.
last_name:$10.
birthday:date7.;
format employee_id:6.
last_name:$10.
birthday:date7.;
datalines;
1247 Garcia 04APR54
1078 Gibson 23APR36
1005 Knapp 06OCT38
1024 Mueller 17JUN53
;
run;
data tempo2;
set tempo;
array temp[*] employee_id;
d=dim(temp);
put (temp[*]) (=);
run;
The array's dimension is 1, but it has 4 observations. How do I get the number of observations for use somewhere else? is there a function or another method for obtaining it?
Thanks in advance.
In SAS an array is only a shortcut list of variables so I don't think it will give you what you want here.
Dimension will always be 1, because you only have one variable.
If you explain what you're trying to do, we may be able to suggest alternative approaches.
@Datino wrote:
Hello,
So I have an array like this:
data tempo; input employee_id:6. last_name:$10. birthday:date7.; format employee_id:6. last_name:$10. birthday:date7.; datalines; 1247 Garcia 04APR54 1078 Gibson 23APR36 1005 Knapp 06OCT38 1024 Mueller 17JUN53 ; run; data tempo2; set tempo; array temp[*] employee_id; d=dim(temp); put (temp[*]) (=); run;
The array's dimension is 1, but it has 4 observations. How do I get the number of observations for use somewhere else? is there a function or another method for obtaining it?
Thanks in advance.
Thank you. I have an ID and a last_modification_dt variables, each loaded in an array. For each ID there are several last_modification_dt values.
What I want to do is compare obs1 date versus obs2 date, if the difference between them is less than 7 days, increase a counter and do obs2 date versus obs3 date and so on.
It has to be done with arrays.
Why does it have to be done with arrays? Your sample data has no relation to your question below so please provide additional data that reflects your situation and what you're expecting as output. Since this is likely homework, include anything you've tried so we can point you in the right direction.
@Datino wrote:
Thank you. I have an ID and a last_modification_dt variables, each loaded in an array. For each ID there are several last_modification_dt values.
What I want to do is compare obs1 date versus obs2 date, if the difference between them is less than 7 days, increase a counter and do obs2 date versus obs3 date and so on.
It has to be done with arrays.
Yeah sorry, it's part of a more complex excercise but I didn't want to ask for the whole solution and figure out some things on my own.
The problem is the one I described in my last post.
There's one ID variable and one last_modification_dt variable. Some IDs have several last modification dates. For each ID with more than one last_modification_dt, I have to find out if the difference between them is less than 7 days, and how many 'less than 7 days diff' are there for each ID.
I thought I would be able to do it with an array but there doesn't seem to be a simple way for me to reference each observation inside the variable in it.
@Datino wrote:
Yeah sorry, it's part of a more complex excercise but I didn't want to ask for the whole solution and figure out some things on my own.
The problem is the one I described in my last post.
There's one ID variable and one last_modification_dt variable. Some IDs have several last modification dates. For each ID with more than one last_modification_dt, I have to find out if the difference between them is less than 7 days, and how many 'less than 7 days diff' are there for each ID.
I thought I would be able to do it with an array but there doesn't seem to be a simple way for me to reference each observation inside the variable in it.
You should be able to use DIF() and or RETAIN, though a SQL join is probably easier. If you provide sample data and expected output you'll likely get a solution.
May be with nobs= in set statement?
data tempo;
input employee_id:6.
last_name:$10.
birthday:date7.;
format employee_id:6.
last_name:$10.
birthday:date7.;
datalines;
1247 Garcia 04APR54
1078 Gibson 23APR36
1005 Knapp 06OCT38
1024 Mueller 17JUN53
;
run;
data tempo2;
set tempo nobs=nobs;
array temp[*] employee_id;
d=dim(temp);
put (temp[*]) (=) nobs=;
run;
Either way, nobs= is equal number of obs in dataset at compile time
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.
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.