BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
HijB
Fluorite | Level 6

I have more than 80 variables for patients with multiple ID  . 

the data looks like:

IDdaawgdetc. 
11.. 
1.1. 
1.1. 
1... 
2.11 
2..1 
3... 
31.. 
3... 

how can I repeat the same value for each variable  for the same ID, So the data would like this 

IDdaawgdetc. 
111. 
111. 
111. 
111. 
2.11 
2.11 
31.. 
31.. 
31.. 
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
Here's one approach.

proc summary data=have nway;
var da -- gd;
by id;
output out=maxvals max=;
run;

For that step, use the name of the last variable instead of gd. Then merge these maximum values back into the original data:

data want;
merge maxvals (drop= _type_ _freq_) have (keep = id);
by id;
run;

SQL supports similar features. But it doesn't support lists of variables. So it would force you to type out the complete list of variable names.

View solution in original post

8 REPLIES 8
Astounding
PROC Star
Here's one approach.

proc summary data=have nway;
var da -- gd;
by id;
output out=maxvals max=;
run;

For that step, use the name of the last variable instead of gd. Then merge these maximum values back into the original data:

data want;
merge maxvals (drop= _type_ _freq_) have (keep = id);
by id;
run;

SQL supports similar features. But it doesn't support lists of variables. So it would force you to type out the complete list of variable names.
HijB
Fluorite | Level 6

Thank you for your response, I did not mention earlier than I also have around 4 million observations, merging any file takes time and freezes the software, is there a way around it?

LinusH
Tourmaline | Level 20

The data step merge usually doesn't require much computer resorrces, like sorting, SQL joins and aggregation steps.

So the questions is what's going on in your computer?

Make sure you have the necessary space for your saswork location.

Check any Windows logs for messages, and also Task Manager while executing your step.

Data never sleeps
Astounding
PROC Star

Buy a new computer?  Pretty much any computer built in the last 10 years could handle this amount of data in less than a minute.  So try it this way.

 

Take a subset of your data (let's say ID values of 1, 2, and 3).  Get the program working for that subset.  Once you have a working program, try applying it to the full data set.

 

Good luck.

HijB
Fluorite | Level 6

this is a new computer I only had it for a month but every time I run the whole dataset the sas software not the computer freezes.  

andreas_lds
Jade | Level 19

@HijB wrote:

this is a new computer I only had it for a month but every time I run the whole dataset the sas software not the computer freezes.  


Strange, this should not happen. Are the latest updates applied to the sas installation? How much memory is installed?

andreas_lds
Jade | Level 19

Why do you want to keep n obs for each patient all having the same data?

yabwon
Onyx | Level 15

Double DOW-loop can do it too:

 

data have;
  input ID	da	aw	gd;
cards;
1	1	.	.	 
1	.	1	.	 
1	.	1	.	 
1	.	.	.	 
2	.	1	1	 
2	.	.	1	 
3	.	.	.	 
3	1	.	.	 
3	.	.	.	 
;
run;
proc print;
run;


%let list_of_vars = da aw gd;
%let num_of_vars = 3;

data want;
  do until(last.ID);
    set have;
    by ID;

    array V(i) &list_of_vars.;
    array T [&num_of_vars.]; 
    drop t:;

    do over V;
      t[i] = V <> t[i];
    end;
  end;

  do over V;
    V = t[i];
  end;

  do until(last.ID);
    set have(drop=&list_of_vars.);
    by ID;
    output;
  end;
run;
proc print;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 872 views
  • 3 likes
  • 5 in conversation