BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I'm just starting using SAS...I received a file in his format:

Client...SKU....Volume
3020....1000.....10
...........1001......3
............1002..... 7
5505.... 2001.....15
..... ......1005 .....6
............1004.....30

I need to complete the blank with the previus value, for exemle, for line2 the client is 3020 too. How could i do it? A friend toldmeto use Retain statement but did not work.

I tried this code:

Data test;
Set test;

Retain Client;
If _n_=1 then Client=NEW_CLIENT;
Else do;
If NEW_CLIENT=’’ then NEW CLIENT=CLIENT;
Else Client=NEW_CLIENT;
End;
Run;

Thanks
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
The _N_ condition is only in effect with the first observation. You will need to use a sorted input file and use a BY statement with the key variables, and retain the important variable(s) using the IF FIRST. THEN ; condition.

Check the SAS support http://support.sas.com/ website for DATA STEP PROGRAMMING discussion and using a BY statement and the FIRST. and LAST. conditions for additional details.

Scott Barry
SBBWorks, Inc.
Peter_C
Rhodochrosite | Level 12
data latest( keep= client sku volume ) ;
* assuming the name of the raw data is CLIENTS ;
set clients( obs= 0 ) ; * getting column definitions ;
do while( not finished ) ;
set clients( rename= ( client= rawC )) end= finished ;
client = coalesce( rawC, client ) ;
output ;
end ;
stop ;
run ;

if column CLIENT is character, use function COALESCEC() rather than COALESCE()


Message was edited by: Peter.C getting column definitions was intended as comment, prefix with *


Message was edited by: Peter.C
deleted_user
Not applicable
getting column definitions - Sas did not recognized. I couldn't make it work

I'm not a programmer...I'm a mkt consutant and i have a huge amont of data to manipulate. Message was edited by: elilika
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If willing to solve the problem (regardless of your focus/perspective), you will need to explain what code you attempted and exactly what error occurred or further explain "getting column definitions - Sas did not recognized. I couldn't make it work".

Scott Barry
SBBWorks, Inc.
deleted_user
Not applicable
Try the following Code. Hope this will help.



data test;
input client sku volume ;
cards;
3020 1000 10
. 1001 3
. 1002 7
5505 2001 15
. 1005 6
. 1004 30
;
run;

data test1(drop=client rename=(temp=client));
set test;
by client notsorted;
retain temp;
if first.client and client ne . then temp=client;
client=temp;
run;

~Sukanya E
deleted_user
Not applicable
Thanks Sukanya, it worked!
:-) Message was edited by: elilika
Peter_C
Rhodochrosite | Level 12
sorry my proposal had a mistake.
As a comment, the text "getting column definitions" should have been prefixed with an asterisk.
I have updated the code in the earlier message

hope it works for you now.
good luck

PeterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 1029 views
  • 0 likes
  • 3 in conversation