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
Opal | Level 21
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
Opal | Level 21
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
Opal | Level 21

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
PROC Star

@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
PROC Star

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

yabwon
Meteorite | Level 14

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



SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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